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

Sarfaraz Mohammed 1 Reputation point
2021-09-07T21:03:25.44+00:00

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 = ????

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,449 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. P a u l 10,406 Reputation points
    2021-09-08T02:01:13.603+00:00

    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://learn.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://learn.microsoft.com/en-us/dotnet/api/azure.storage.blobs.models.blobitemproperties?view=azure-dotnet#properties

    0 comments No comments