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.
Here's my code to list 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 to list my blob:
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));
}
In my web form, i call my ListContainer methods in the page load:
protected void Page_Load(object sender, EventArgs e)
{
BlobService list = new BlobService();
ListBox2.DataSource = list.ListContainer();
ListBox2.DataBind();
}
When i load the project, my containers are listed in the ListBox 2. What i need is that when i click on a container, it will display the blobs it contains in another ListBox. I tried the following but nothing happens:
protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListBox2.SelectedItem.Equals("http://127.0.0.1:10000/devstorageaccount1/mycontainer"))
{
BlobService list = new BlobService();
ListBox1.DataSource = list.ListBlob("mycontainer");
ListBox1.DataBind();
}
else
{
//Error Message
}