gpt4 book ai didi

c# - Azure Blob 存储列表容器和 Blob

转载 作者:行者123 更新时间:2023-11-30 15:22:43 25 4
gpt4 key购买 nike

我正在开发一个 Azure 存储项目,我需要在容器中上传和下载 blob,并在列表框中列出容器和 blob。我无法在列表框中显示容器和 blob。

这是我要列出的代码: enter image description here

最后是我调用上传、下载和列表方法的界面背后的代码:

enter image description here

最佳答案

当您单击 Web 表单中的 Button3 时看不到任何结果的原因是您没有从 ListBlob 方法中获取任何数据。

更改 ListBlob 方法以返回如下结果:

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

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

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

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

// Loop over items within the container and output the length and URI.
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof (CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob) item;

blobs.Add(string.Format("Block blob of length {0}: {1}", blob.Properties.Length, blob.Uri));

}
else if (item.GetType() == typeof (CloudPageBlob))
{
CloudPageBlob pageBlob = (CloudPageBlob) item;

blobs.Add(string.Format("Page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri));

}
else if (item.GetType() == typeof (CloudBlobDirectory))
{
CloudBlobDirectory directory = (CloudBlobDirectory) item;

blobs.Add(string.Format("Directory: {0}", directory.Uri));
}
}

return blobs;
}

与您的网络表单相比,我假设您有一个名为 ListBox1 的列表框。调用该方法如下:

protected void Button3_Click(object sender, EventArgs e)
{
ListBox1.DataSource = GetBlobs();
ListBox1.DataBind();
}

关于c# - Azure Blob 存储列表容器和 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35321499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com