var blobClient = new CloudBlobClient(new Uri("blobEndpoint"), new StorageCredentials("accountName", "accountKey")); var container = blobClient.GetContainerReference("mycontainer"); var blob = container.GetBlockBlobReference("myfile.txt"); // Get the ETag value of the file blob.FetchAttributes(null, new AccessCondition(), null); // Use the ETag value in the AccessCondition to ensure the file has not been modified var condition = new AccessCondition { IfMatchETag = blob.Properties.ETag }; // Upload a new version of the file if it has not been modified using (var fileStream = File.OpenRead("myfile.txt")) { blob.UploadFromStream(fileStream, condition); }
var blobClient = new CloudBlobClient(new Uri("blobEndpoint"), new StorageCredentials("accountName", "accountKey")); var container = blobClient.GetContainerReference("mycontainer"); var blob = container.GetBlockBlobReference("myfile.txt"); // Get the date and time that the file was last modified blob.FetchAttributes(null, new AccessCondition(), null); // Use the date and time in the AccessCondition to prevent overwriting the file if it has been modified var condition = new AccessCondition { IfModifiedSinceTime = blob.Properties.LastModified.Value.DateTime }; // Upload a new version of the file if it has not been modified using (var fileStream = File.OpenRead("myfile.txt")) { blob.UploadFromStream(fileStream, condition); }This example also uses the Microsoft.Azure.Storage.Blob package library.