我正在尝试在 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。
根据 this documentation ,我们可以发现在创建 mydirectory 之前,父目录必须已经存在于共享中。
关于azure - 在azure文件共享中创建目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42758229/