c# - Azure 文件共享属性 LastModified 的 null 值

标签 c# azure azure-files

  // 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"]));

            var test = sourceName.Properties.LastModified;

但是sourceName.Properties.LastModified为空

甚至fileShare.Properties.LastModified为空

当我尝试获取 Azure 文件共享的 LastModified 属性时,我得到 null。

最佳答案

原因是每次调用 GetRootDirectoryReference() 时,都会创建一个 FileItem 的新实例,导致其属性被初始化为其默认值,同样如此行为与使用 GetBlockBlobReference() 时相同。

您需要做的是调用 FetchAttributes 来填充所有属性。

请注意,获取属性时,您不需要创建对象的新实例。

你可以关注这个post它引用了 blob,但也与您的错误有关。

<小时/>

您要求的示例是:

public static void ListContainerMetadataAsync(CloudBlobContainer container)
{
    // Fetch container attributes in order to populate the container's 
       properties and metadata.
     container.FetchAttributes();

    // Enumerate the container's metadata.
    Console.WriteLine("Container metadata:");
    foreach (var metadataItem in container.Metadata)
    {
        Console.WriteLine("\tKey: {0}", metadataItem.Key);
        Console.WriteLine("\tValue: {0}", metadataItem.Value);
    }
}

您可以在 docs.microsoft 阅读更多内容.

关于c# - Azure 文件共享属性 LastModified 的 null 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52036304/

相关文章:

Azure函数队列触发器: how to set time delay for dequeue message

c# - Azure 文件存储 : Create nested directories

c# - 如何在点击时交换图像?

C# Entity Framework Core - 对象名称无效,无法更新数据库

c# - 代码分析 c# .NET CA1822

azure - 如何从 Azure DevOps Pipeline 读取 Azure 文件共享文件

c# - 上传到 Azure 文件存储因大文件而失败

c# - 字符串到双数。(格式##.###,##)

azure - CPU 工作负载低时自动关闭 Azure VMSS 实例

Azure 空间 anchor - 在 HoloLens 上获取云空间异常