【发布时间】:2016-02-13 14:01:24
【问题描述】:
我已经使用 WCF 创建了一个 Azure 云服务,我试图在其中列出我的容器和 blob。我已经能够列出我的容器和 blob。我想要做的是,当我在我的 ListBox 中选择一个容器时,它将显示它包含在另一个 ListBox 中的 blob。
这是列出我的容器的代码:
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;
}
列出我的 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));
}
在我的 web 表单中,我在页面加载中调用我的 ListContainer 方法:
protected void Page_Load(object sender, EventArgs e)
{
BlobService list = new BlobService();
ListBox2.DataSource = list.ListContainer();
ListBox2.DataBind();
}
当我加载项目时,我的容器列在 ListBox 2 中。我需要的是,当我单击一个容器时,它将显示它包含在另一个 ListBox 中的 blob。我尝试了以下但没有任何反应:
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
}
【问题讨论】: