Akash.P Akash.P - 3 months ago 10
C# Question

Get last modified date of latest file in a storage account

Scenario:program that can look at storage account and process all new & modified files and take an action if there is any new ones. For that i want to find the last modified date of the latest file .How can i achieve this?Anyone please help me.

namespace ListStorageAccntFiles
{
class Program
{
static void Main(string[] args)
{
Console.Clear();

CloudStorageAccount StorageAccount =
CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var BlobClient = StorageAccount.CreateCloudBlobClient();
var Container = BlobClient.GetContainerReference("samples‐workitems");

//Code to list the blobnames in Console
var list = Container.ListBlobs();
List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b =>b.Name).ToList();

blobNames.ForEach(Console.WriteLine);
//Code for the remaining

}
}
}

Answer

Finally got the answer(simply last modified date of all files,not the specific latest file).

//Code to get the last modified date

CloudBlockBlob blockBlob = Container.GetBlockBlobReference(blobName);
blockBlob.FetchAttributes();
var lastModifiedDate = blockBlob.Properties.LastModified;
Console.WriteLine(lastModifiedDate);  
Comments