marchica marchica - 1 year ago 152
C# Question

Update LastModified on an Azure Blob

I'm porting code to work with Azure's Storage SDK in C#.

Traditionally, I'd call this to update modified the last write/modified time of a file:

File.SetLastWriteTimeUtc(fileName, lastWriteTimeUtc);

To update a blob's last modified time, I'm trying to do something like this but can't because LastModified is not accessible:

CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
blob.Properties.LastModified = lastWriteTimeUtc;

Compiler error:

Property or indexer 'Microsoft.WindowsAzure.Storage.Blob.BlobProperties.LastModified' cannot be assigned to -- it is read only

How can I update the LastModified property? It won't always be updated to the current time, so I can't just reupload/touch the file.

Answer Source

What you want is effectively a "touch" operation. You must re-upload the BLOB to change the LastModified property.


If you want to manage your own custom last modified variable, the best thing you can probably do is store a custom "Last Modified" field in your BLOB and use that yourself, vs relying on the native LastModified provided by Azure BLOB.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download