Replace the Contents inside Azure Storage

Is there are any way to replace a file if the same name exists? I can't see any replace method in Azure Storage. Here is my code:

var client = new CloudBlobClient(
      new Uri(""), credentials);
var container = client.GetContainerReference("cakepictures");
await container.CreateIfNotExistsAsync();
var perm = new BlobContainerPermissions();
perm.PublicAccess = BlobContainerPublicAccessType.Blob;
await container.SetPermissionsAsync(perm);
var blockBlob = container.GetBlockBlobReference(newfilename + i + file.FileType);
using (var fileStream = await file.OpenSequentialReadAsync())
    await blockBlob.UploadFromStreamAsync(fileStream);

Is there anything that I could add into this code so that it replaces existing or same file name?


If a blob exists in blob storage and if you upload another file with the same name as that of the blob, old blob contents will automatically be replaced with the contents of new file. You don't have to do anything special.

As Gaurav also mentioned in his answer, the default behavior of UploadFromStream API is to overwrite if the blob already exists.

Need Your Help

Input Field, wrap text instead of extending horizontally

html css input text word-wrap

I have an input field, a user will write text inside but when the text is to long it just extends horizontally instead of dropping down vertically.

Registering a custom JsonConverter globally in Json.Net


Using Json.Net, I have properties in my objects which need special care in order to serialize / deserialize them. Making a descendant of JsonConverter, I managed to accomplish this successfully. Th...