Last active
February 1, 2019 04:19
-
-
Save donma/6fc0a28aa2f0fc1309a60afb1b1dfa8a to your computer and use it in GitHub Desktop.
Azure Blob Storage List All Directories in Directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connsctionString = "your_connection_string"; | |
var cloudStorage = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connsctionString); | |
var cloudBlobClient = cloudStorage.CreateCloudBlobClient(); | |
var cloudBlobContainer = cloudBlobClient.GetContainerReference("donmablogsample"); | |
var resultCreateContainer = cloudBlobContainer.CreateIfNotExistsAsync().Result; | |
Console.WriteLine("donmablogsample create already."); | |
Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory = | |
cloudBlobContainer.GetDirectoryReference("TEST2/TEST21/"); | |
var res = new List<string>(); | |
Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken continuationToken = null; | |
do | |
{ | |
var listingResult = cloudBlobDirectory.ListBlobsSegmentedAsync(continuationToken).Result; | |
continuationToken = listingResult.ContinuationToken; | |
res.AddRange(listingResult.Results.Where(x => x as Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory != null).Select(x => x.Uri.Segments.Last()).ToList()); | |
} | |
while (continuationToken != null); | |
Console.WriteLine("Result: " + string.Join("\r\n", res)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment