0

I am trying to get the LastModified date for a blockblob.

I find the block blob the same way as shown in another stackoverflow post: https://stackoverflow.com/a/60082240/2759759

        var cloudStorageAccount = CloudStorageAccount.Parse(variable);
        var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
        var cloudBlobContainer = cloudBlobClient.GetContainerReference(BlobContainerName);
        var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(blobFile);
        var blobDateTime = cloudBlockBlob.Properties.LastModified; // returns null
        var cloudBlockBlob2 = cloudBlockBlob.CreateSnapshot();
        var blobDateTime2 = cloudBlockBlob2.Properties.LastModified; // returns desired date time information

When the above is run, blobDateTime will be null, blobDateTime2 will have the desired information. Why did I need to create a Snapshot in order to get the date last modified? What is least expensive way to get the LastModified information. Creating a snapshot isn't instantaneous so it's probably doing more in the background than what I need to do if I just want the modified date.

Fractal
  • 1,748
  • 5
  • 26
  • 46

1 Answers1

0

Here is the fix. I just needed to add the FetchAttributes() line of code.

    var cloudStorageAccount = CloudStorageAccount.Parse(variable);
    var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
    var cloudBlobContainer = cloudBlobClient.GetContainerReference(BlobContainerName);
    var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(blobFile);
    cloudBlockBlob.FetchAttributes();
    var blobDateTime = cloudBlockBlob.Properties.LastModified; // returns good date time information

I don't understand why none of the other examples in Stack Overflow needed to add a 'FetchAttributes()' in order to retrieve the date modified info.

Fractal
  • 1,748
  • 5
  • 26
  • 46