+4 votes
2 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.

2 Answers

+11 votes
by (10.6k 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();  
0 votes
by (37.4k 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();  

}

...