繁体   English   中英

获取存储帐户中最新文件的上次修改日期

[英]Get last modified date of latest file in a storage account

方案:该程序可以查看存储帐户并处理所有新文件和修改过的文件,如果有任何新文件,则采取措施。 为此,我想找到最新文件的最后修改日期。我该如何实现?任何人都可以帮助我。

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

    }
  }
}

最终得到答案(仅是所有文件的最后修改日期,而不是特定的最新文件)。

//Code to get the last modified date

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

如vivek所述,我们可以使用LastModifyedUtc来获取最新的修改文件。 我们还可以使用webjob blob触发器来监视最新更改,请查看我在您以前的帖子中的回复。

您可以使用以下代码。

CloudFile file = yourDirectory.GetFileReference(fileName);
file.FetchAttributes();
DateTime lastWriteDate = DateTime.Parse(file.Properties.LastModified.ToString());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM