sebastian.roibu
sebastian.roibu

Reputation: 2859

Create directory structure in azure file share

I am trying to create a folder structure in azure file share. I am doing this from a web app. My code looks like this:

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

When I run this code nothing happens. No exception is thrown but no folder is created. What am I doing wrong?

Edit: Meanwhile, I found this answer which says that I need to create level by level. I will try that.

Upvotes: 1

Views: 2574

Answers (1)

Fei Han
Fei Han

Reputation: 27793

If you use fiddler to capture request while you create multi-level directory structure via Azure storage SDK, you will find it sends a request like this.

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

and you will find status is 404.

enter image description here

According to this documentation, we could find that the parent directory must already exist within the share before mydirectory can be created.

Upvotes: 1

Related Questions