Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
3 views
in Azure by (13.2k points)

I just want to know whether a blob exists in a particular container or not. Simple question right!

I'll download it if yes else I'll do something else . I've done a lot of research but it seems that it doesn't exist.

3 Answers

+11 votes
by (10.5k points)
edited by
  • Good news for you. It does exist in the new API. You can use exists () function call.  
  • Just remember to use GetBlockBlobReference which doesn't perform the call to the server.
  • You can use the given syntax:

public static bool BlobExists(CloudBlobClient client, 

    string containerNaHow to get the azure account tenant Id?

me, string key)

{

     return client.GetContainerReference(containerName)

                  .GetBlockBlobReference(key)

                  .Exists();
You can learn more about various types of Azure storage on Azure Storage Tutorial.
0 votes
by (40.7k points)

The new API has the .Exists() function call. Just make sure that you use the GetBlockBlobReference, which doesn't perform the call to the server.

Want to learn Blob storage from scratch! Here's the right video for you provided by Intellipaat:

It makes the function as easy as:

public static bool BlobExistsOnCloud(CloudBlobClient client, 

    string containerName, string key)

{

     return client.GetContainerReference(containerName)

                  .GetBlockBlobReference(key)

                  .Exists();  

}

0 votes
by (2.8k points)

The new API has the .Exists() function call. Ensure that you are using the GetBlockBlobReference,as it doesn’t make server calls . It simplifies the function into:

public static bool BlobExistsOnCloud(CloudBlobClient client, 

string containerName, string key) 

{

 return client.GetContainerReference(containerName)

 .GetBlockBlobReference(key) 

.Exists(); 

}

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...