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

标签 c# azure azure-files

我的代码如下所示

CloudFileClient client = ...;

client.GetShareReference("fileStorageShare")
    .GetRootDirectoryReference()
    .GetDirectoryReference("one/two/three")
    .Create();

如果目录一或目录二不存在,则会出现此错误。有没有办法通过一次调用来创建这些嵌套目录?

最佳答案

这是不可能的。 SDK不支持这种方式,需要一一创建。

问题已提交here .

如果你想一一创建它们,可以使用以下示例代码:

static void NestedDirectoriesTest()
{
   var cred = new StorageCredentials(accountName, accountKey);
   var account = new CloudStorageAccount(cred, true);
   var client = account.CreateCloudFileClient();
   var share = client.GetShareReference("temp2");
   share.CreateIfNotExists();
   var cloudFileDirectory = share.GetRootDirectoryReference();

   //Specify the nested folder
   var nestedFolderStructure = "Folder/SubFolder";
   var delimiter = new char[] { '/' }; 
   var nestedFolderArray = nestedFolderStructure.Split(delimiter);
   for (var i=0; i<nestedFolderArray.Length; i++)
   {
       cloudFileDirectory = cloudFileDirectory.GetDirectoryReference(nestedFolderArray[i]);
       cloudFileDirectory.CreateIfNotExists();
       Console.WriteLine(cloudFileDirectory.Name + " created...");
   }
}

关于c# - Azure 文件存储 : Create nested directories,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52593360/

相关文章:

c# - 日历以各种频率重复

c# - 使用 TransactionScope 时出现异常 "The operation is not valid for the state of the transaction"

azure - 在 Azure 应用服务上运行的 ASP.NET Core 3.1 应用针对 1.6 MB json 负载抛出 EPIPE 错误

azure - 如何检查哪个Azure资源正在使用特定的IP地址?

c# - Azure 文件存储 SMB 列出目录中的文件速度很慢

c# - 无法访问 Azure 中的文件系统

c# - 在 C# 上解析 Delphi 项目文件

c# - 如何将asp.net core mvc项目分离成多个程序集(.dll)?

php - Webapp IP 的 Azure MySQL 连接安全

azure - 从 Azure 文件共享将内容加载到 Azure 静态 Web 应用程序,管理用户访问权限