Pure.Krome Pure.Krome - 1 year ago 165
C# Question

How to list all the Directories or Files, from a root Directory, in Azure File Storage -and- using the .NET Storage SDK?

I'm trying to figure out how to

  • list all the directories under a single directory


  • list all the files in a single directory

using the Azure Storage Client Library for .NET.

The MS docs do give us an API endpoint to hit ... but I'm hoping to use the .NET Storage SDK which handles a lot of the low level communications (authentication, etc) for me.

Can anyone show me what it takes to do this, please?

Answer Source

Please take a look at our File storage sample for some code that shows how to do this.


//***** Get list of all files/directories on the file share*****//

// List all files/directories under the root directory.
Console.WriteLine("Getting list of all files/directories under the root directory of the share.");

IEnumerable<IListFileItem> fileList = cloudFileShare.GetRootDirectoryReference().ListFilesAndDirectories();

// Print all files/directories listed above.
foreach (IListFileItem listItem in fileList)
    // listItem type will be CloudFile or CloudFileDirectory.
    Console.WriteLine("    - {0} (type: {1})", listItem.Uri, listItem.GetType());

Console.WriteLine("Getting list of all files/directories in the file directory on the share.");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download