Last active
February 1, 2019 04:18
-
-
Save donma/2709026f92bc3ef6a806eae1ac187471 to your computer and use it in GitHub Desktop.
Azure Blob Storage List All Files 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>(); | |
//這種方法在 Azure Storge 包括 table 很常使用 | |
Microsoft.WindowsAzure.Storage.Blob.BlobContinuationToken continuationToken = null; | |
do | |
{ | |
var listingResult = cloudBlobDirectory.ListBlobsSegmentedAsync(continuationToken).Result; | |
continuationToken = listingResult.ContinuationToken; | |
res.AddRange(listingResult.Results.Select(x => System.IO.Path.GetFileName(x.Uri.AbsolutePath)).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