I need to list names of Azure Blob file names. Currently I m able to list all files with URL but I just need list of names. I want to avoid parsing names. Can you please see
We can get some additional info like Size, Modified date and Name.
CloudStorageAccount backupStorageAccount = CloudStorageAccount.Parse(YOUR_CON_STRING);
var backupBlobClient = backupStorageAccount.CreateCloudBlobClient();
var backupContainer = backupBlobClient.GetContainerReference("CONTAINER");
var blobs = backupContainer.ListBlobs().OfType<CloudBlockBlob>().ToList();
foreach (var blob in blobs)
{
string bName = blob.Name;
long bSize = blob.Properties.Length;
string bModifiedOn = blob.Properties.LastModified.ToString();
}
Also you can download a specific file by Name.
// Download file by Name
string fileName = "Your_file_name";
CloudBlockBlob blobFile = backupContainer.GetBlockBlobReference(fileName);
blobFile.DownloadToFile(@"d:\"+ fileName, System.IO.FileMode.Create);
You can access the BlobProperties
to get the name:
foreach (object o in list)
{
BlobProperties bp = o as BlobProperties;
if (bp != null)
{
BlobProperties p = _Container.GetBlobProperties(bp.Name);
var name = p.Name; // get the name
}
}