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

Create directory structure in azure file share

我正在尝试在 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\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

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