question

SarfarazMohammed-5553 avatar image
0 Votes"
SarfarazMohammed-5553 asked Sumarigo-MSFT commented

How to get "LastModifiedDate" for a file in Azure Blob Storage Container?


I am retreiving a file from Azure Blob Storage Container and trying to get its last modified date value.
Using the latest .NET SDK for Azure and I cant seem to find documentation as to how to reference the LastModifiedDate attribute.

Below is my source code. I have a variable called results which has a couple methods, main one being LastUpdatedDate which should be set to the LastModifiedDate from the container file.

var results = new Data();

BlobServiceClient blobServiceClient = new BlobServiceClient(---);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(---);
BlobClient blobClient = containerClient.GetBlobClient(---);

results.LastUpdatedDate = ????

dotnet-csharpazure-blob-storage
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Paul-5034 avatar image
0 Votes"
Paul-5034 answered Sumarigo-MSFT commented

Provided you don't have too many blob items in your container, you can use this to output all the BlobItem inside your containerClient:

 await foreach (BlobItem blobItem in containerClient.GetBlobsAsync())
 {
     Console.WriteLine("\t" + blobItem.Name);
 }

BlobItem has a "Properties" property:
https://docs.microsoft.com/en-us/dotnet/api/azure.storage.blobs.models.blobitem?view=azure-dotnet

And "Properties" is a BlobPropertyItems class that has a "LastModified" property of type DateTimeOffset?:
https://docs.microsoft.com/en-us/dotnet/api/azure.storage.blobs.models.blobitemproperties?view=azure-dotnet#properties

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.