Getting null value for Azure blob last modified property

后端 未结 2 1361
终归单人心
终归单人心 2021-01-15 12:48

I\'m getting null when I\'m trying to fetch LastModified property of Azure Blob, below is the snippet for the same.

Cl         


        
相关标签:
2条回答
  • 2021-01-15 13:03

    For those who use a newer version of CloudBlockBlob and FetchAttributes does not exist – use DownloadAttributes instead.

    CloudBlockBlob blockBlob = container.GetBlockBlobReference(blob.ToString());
    blockBlob.DownloadAttributes();
    var timemodified = blockBlob.Properties.LastModified;
    
    0 讨论(0)
  • 2021-01-15 13:17

    Reason you're getting this behavior is because when you execute following line of code:

    CloudBlockBlob blockBlob = container.GetBlockBlobReference(blob.ToString());
    

    It essentially creates a new instance of CloudBlockBlob object and it's properties are initialized to the default value. You would need to call FetchAttributes method on this to fill the properties.

    Also, when you list the blobs the properties of the blob are fetched as well. So you need not create a new instance of CloudBlockBlob. Simply use the blob object you got as listing result and use the properties from there. So your code would be:

            foreach (var blob in blobs)
            {
                var timemodified = blob.Properties.LastModified;
            }
    
    0 讨论(0)
提交回复
热议问题