Reputation: 125
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
}
}
}
Upvotes: 0
Views: 6145
Reputation: 365
You can use below code.
CloudFile file = yourDirectory.GetFileReference(fileName);
file.FetchAttributes();
DateTime lastWriteDate = DateTime.Parse(file.Properties.LastModified.ToString());
Upvotes: 0
Reputation: 125
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);
Upvotes: 2
Reputation: 3293
As vivek mentioned, we can use LastModifyedUtc to get the lastest modified file. We can also use webjob blob trigger to monitor the latest change, please have a look at my reply in your previous post.
Upvotes: 0