Question

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;
blob.SetProperties();

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.

Was it helpful?

Solution 3

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

EDIT

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.

OTHER TIPS

Azure allows you to add METADATA to the containers and blobs. LastModified is an internal property and there is no point to let external parties update it - it should reflect its meaning.

In your case, it seems that you want to keep old values after migrating content, and content might not allow to add property inside. Say, it is an image.

In this case use Metadata to add and read additional properties. Article about Metadata on MSDN

You can use SetMetadata method to update LastModified property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top