我们如何跟踪 azure 文件存储文件夹是否更新?
How do we track azure file storage folder is updated or not?
我有 azure 文件存储,里面有其他文件夹。
我想检查或跟踪该文件夹的最后更新时间?
我已经完成了一个简单的控制台应用程序来从该位置获取所有文件 -
// Get list of all files/directories on the file share
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);
var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));
IEnumerable<IListFileItem> fileList = sourceName.ListFilesAndDirectories();
CloudFileDirectory destinationDir = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["destinationName"]));
foreach (IListFileItem listItem in fileList)
{
// gives me all file records
}
我试图这样得到它,但它是 null
。
var test = sourceName.Properties.LastModified;
因为 null 我不能使用这个查询:(
var latest= fileShare.GetRootDirectoryReference().ListFilesAndDirectories()
.OfType<CloudFileShare>()
.OrderByDescending(m => m.Properties.LastModified)
.ToList()
.First();
i just noticed that , i have uploaded one new file just now into that folder but still LastModified is old date , it means LastModified is separate for that folder and file :O what to do now ?
I want to check whether any new file is updated into any sub-fodler of main folder or not within 24hr.
我想知道如何检查该源文件夹的最后更新文件日期时间?
为什么 LastModified 为空?
To retrieve property values, call the FetchAttributesAsync
method on your blob or container to populate the properties, then read the values.
当您 运行 您的控制台应用程序时,它实质上会创建一个 CloudFileShare
对象的新实例,并将其属性初始化为默认值。您需要对此调用 FetchAttributes
方法来填充属性。
此外,当您列出文件的属性时,文件的属性也会被提取,您将不需要创建 CloudFileShare
的新实例。你可以参考这个 .
您可以在检索 属性 之前使用 sourceName.FetchAttributes();。我测试了它,它工作正常。请参考以下代码:
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);
var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));
sourceName.FetchAttributes();
var test = sourceName.Properties.LastModified;
我有 azure 文件存储,里面有其他文件夹。 我想检查或跟踪该文件夹的最后更新时间?
我已经完成了一个简单的控制台应用程序来从该位置获取所有文件 -
// Get list of all files/directories on the file share
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);
var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));
IEnumerable<IListFileItem> fileList = sourceName.ListFilesAndDirectories();
CloudFileDirectory destinationDir = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["destinationName"]));
foreach (IListFileItem listItem in fileList)
{
// gives me all file records
}
我试图这样得到它,但它是 null
。
var test = sourceName.Properties.LastModified;
因为 null 我不能使用这个查询:(
var latest= fileShare.GetRootDirectoryReference().ListFilesAndDirectories()
.OfType<CloudFileShare>()
.OrderByDescending(m => m.Properties.LastModified)
.ToList()
.First();
i just noticed that , i have uploaded one new file just now into that folder but still LastModified is old date , it means LastModified is separate for that folder and file :O what to do now ?
I want to check whether any new file is updated into any sub-fodler of main folder or not within 24hr.
我想知道如何检查该源文件夹的最后更新文件日期时间?
为什么 LastModified 为空?
To retrieve property values, call the
FetchAttributesAsync
method on your blob or container to populate the properties, then read the values.
当您 运行 您的控制台应用程序时,它实质上会创建一个 CloudFileShare
对象的新实例,并将其属性初始化为默认值。您需要对此调用 FetchAttributes
方法来填充属性。
此外,当您列出文件的属性时,文件的属性也会被提取,您将不需要创建 CloudFileShare
的新实例。你可以参考这个
您可以在检索 属性 之前使用 sourceName.FetchAttributes();。我测试了它,它工作正常。请参考以下代码:
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);
var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));
sourceName.FetchAttributes();
var test = sourceName.Properties.LastModified;