Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have create a Azure Cloud Service with WCF where i am trying to list my containers and blobs. I've been able to list both my containers and blobs. What i am trying to do is that when i select a container in my ListBox, it will display the blobs it contains in another ListBox.

When my project is load, my containers are already lusted in my ListBox 2. What i am trying to do is that when i click on a specific container, it will display its content in another ListBox1.

What I have tried:

The code for listing my Containers:

public List<string> ListContainer()
{
List<string> blobs = new List<string>();

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("BlobConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

//Get the list of the blob from the above container

IEnumerable<cloudblobcontainer> containers = blobClient.ListContainers();

foreach (CloudBlobContainer item in containers)
{

blobs.Add(string.Format("{0}", item.Uri));
}

return blobs;
}


The code for listing my Blobs:

public List<string> ListBlob(string folder)
{
List<string> blobs = new List<string>();

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("BlobConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(folder);


//Get the list of the blob from the above container
IEnumerable<ilistblobitem> blobList = container.ListBlobs();

//Display the names on the page
string names = string.Empty;

foreach (IListBlobItem item in blobList)
{
blobs.Add(string.Format("Directory {0}", item.Uri));
}


Finally, this is the code i set in my ListBox so that when i select the item "mycontainer" or "test" it will display its content in the ListBox1.

protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListBox2.SelectedItem.ToString() == "mycontainer")
{
BlobService list = new BlobService();
ListBox1.DataSource = list.ListBlob("mycontainer");
ListBox1.DataBind();
}
else if (ListBox2.SelectedItem.ToString() == "test")
{
BlobService list = new BlobService();
ListBox1.DataSource = list.ListBlob("test");
ListBox1.DataBind();

}

It is not working and i really don't know what to do! Hope you can help me!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900