Getting null value for Azure blob last modified property

大城市里の小女人 提交于 2019-12-01 09:56:06

问题


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

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("account");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("folder");
var blobs = container.ListBlobs();
foreach (var blob in blobs)
{
CloudBlockBlob blockBlob =container.GetBlockBlobReference(blob.ToString());
var timemodified = blockBlob.Properties.LastModified;
}

value fetched in blob above is not a CloudBlobDirectory. Thanks in advance for any help.


回答1:


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;
        }


来源:https://stackoverflow.com/questions/40281329/getting-null-value-for-azure-blob-last-modified-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!