How to get the list of names of Azure blob files in a container

0 votes

Was thinking on how to list names of Azure Blob file names. Currently I am able to list all files with URL but I just need list of names. I want to avoid parsing names. Can you please see my below code and guide:

CloudStorageAccount backupStorageAccount = CloudStorageAccount.Parse(blobConectionString);

var backupBlobClient = backupStorageAccount.CreateCloudBlobClient();
var backupContainer = backupBlobClient.GetContainerReference(container);

var list = backupContainer.ListBlobs();
Jun 27, 2018 in Azure by null_void
• 3,220 points
21,799 views

1 answer to this question.

0 votes

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);

Hope this helps!!

To know more about Azure, enroll today with our Azure certification course.

Thanks!!

answered Jun 27, 2018 by club_seesharp
• 3,450 points

Related Questions In Azure

0 votes
1 answer

How can we load a list of Azure blob files recursively?

Actually, there's a simpler way to do ...READ MORE

answered Aug 14, 2018 in Azure by null_void
• 3,220 points
19,531 views
0 votes
1 answer

How to list the subscriptions of a Azure account?

Hi@akhtar, You can get all the subscriptions for ...READ MORE

answered Nov 10, 2020 in Azure by MD
• 95,460 points

edited Jul 4, 2023 by Khan Sarfaraz 1,194 views
0 votes
1 answer

How to determine the number of messages in an Azure Services Bus Queue?

You will get error when you try ...READ MORE

answered Jun 12, 2018 in Azure by null_void
• 3,220 points
4,604 views
0 votes
1 answer

How to get blob-URL after file upload in azure?

Assuming you're uploading the blobs into blob ...READ MORE

answered Sep 27, 2018 in Azure by null_void
• 3,220 points
15,928 views
0 votes
1 answer

How to check if multiple files exist in Azure container?

foreach loop is the most efficient way though. ...READ MORE

answered Mar 4, 2019 in Azure by Prerna
• 1,960 points
3,846 views
0 votes
1 answer

How to create a sub directory in a blob container?

There are two ways:  using the GetDirectoryReference looping through a containers ...READ MORE

answered Mar 26, 2019 in Azure by Prerna
• 1,960 points
12,570 views
0 votes
0 answers

How to create a sub-container in Azure?

How to create a sub-container in Azure ...READ MORE

Jun 28, 2019 in Azure by sabby
• 4,370 points
1,028 views
0 votes
1 answer

How to create a sub-container in Azure?

You can create a container named "content" and ...READ MORE

answered Jun 28, 2019 in Azure by Perry
• 17,100 points

edited Oct 7, 2021 by Sarfaraz 1,953 views
0 votes
1 answer

Azure Blob: How to open a file in browser without downloading it?

First, because I was using a byte[] the controller ...READ MORE

answered Jun 20, 2018 in Azure by club_seesharp
• 3,450 points
24,650 views
0 votes
1 answer

How to upload a file on to Azure Blob storage without writing a code?

You can find the below tools useful ...READ MORE

answered Apr 13, 2018 in Azure by club_seesharp
• 3,450 points
1,592 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP