azure - 在azure文件共享中创建目录结构

标签 azure azure-storage azure-files

我正在尝试在 azure 文件共享中创建文件夹结构。我是通过网络应用程序执行此操作的。我的代码如下所示:

CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(StorageConnectionString);

CloudFileClient cloudFileClient = cloudStorageAccount.CreateCloudFileClient();

//Get a reference for the share
CloudFileShare cloudFileShare = cloudFileClient.GetShareReference(VideosDirectoryName);  

// Get a reference to the root directory for the share.
CloudFileDirectory rootDir = cloudFileShare.GetRootDirectoryReference();

// Try to get a reference for the new folder
CloudFileDirectory sampleDir = rootDir.GetDirectoryReference(storagePath);

//create the directory structure
sampleDir.CreateAsync();

storagePath looks like: 2017\03\13\d68dd25587624b8691a05834466cfc11

当我运行此代码时,没有任何反应。没有抛出异常,但没有创建文件夹。我做错了什么?

编辑:同时,我发现 this answer这说明我需要逐级创建。我会尝试一下。

最佳答案

如果您在通过Azure存储SDK创建多级目录结构时使用fiddler捕获请求,您会发现它会发送这样的请求。

PUT https://{storageaccount}.file.core.windows.net/{sharename}/2017%5C03%5C13%5C0945682c-2214-49a5-93ba-10ac105532ea?restype=directory

您会发现状态为404

enter image description here

根据 this documentation ,我们可以发现在创建 mydirectory 之前,父目录必须已经存在于共享中。

关于azure - 在azure文件共享中创建目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42758229/

相关文章:

powershell - 查询 Azure Active Directory 的 UPN 和主 SMTP 地址,然后导出到 CSV

powershell - 使用 PowerShell(通过 Get-AzureStorageBlobContent)下载 Azure blob 非常慢,但通过 Azure Explorer 等下载速度很快?

java - Azure 存储服务 REST API : Create Container

azure-databricks - Databricks 和 Azure 文件

azure - 克服 5TB Azure 文件存储共享限制

.net - Windows Azure,解决实例和粘性 session

c# Azure Mobile Apps - 添加新模型不起作用

azure - Visual Studio Team Services 在 Azure 上部署 - 错误 default-publish.ps1 在 azure vm 上不存在

.net - 使用哪个 Azure Blob 客户端库? Microsoft.Azure.Storage.Common 或 WindowsAzure.Storage?

c# - 以编程方式下载 Azure 文件共享文档