Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Delete an azure blob by blob Name

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 144
    Comment on it

    We can delete any blob from our storage by identifying it with its name.

    Here is the sample code for deleting a blob from azure storage.

      StorageCredentials creds = new StorageCredentials("StorageAcocuntName", "StorageAccountKey");
      CloudBlobClient blobStorage = new CloudBlobClient(new Uri("BaseURI of storage account"), creds);
      CloudBlobContainer container = blobStorage.GetContainerReference("Your Container Name");
      CloudBlob blob = container.GetBlobReference("Your Blob Name");
      blob.DeleteIfExists();

    In the code above, First we are creating object of StoraeCredentials class by passing the storageaccountname and storageaccountkey. Then we get the reference of cloudblobclient with the help of these credentials and base uri of azure storage. Next we need to get the reference of the container in which the blob is saved. This we can get with the help of container name. Once we have got the reference of container, we use container.GetBlobReference which gives us the cloud blob object with the help of its name.

    blob.DeleteIfExists() method deletes the blob if it exists else it does not throw any error.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: