Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure Blob存储列表容器和Blob_C#_.net_Azure_Azure Storage Blobs - Fatal编程技术网

C# Azure Blob存储列表容器和Blob

C# Azure Blob存储列表容器和Blob,c#,.net,azure,azure-storage-blobs,C#,.net,Azure,Azure Storage Blobs,我正在从事一个Azure存储项目,我需要上传和下载容器中的blob,并在列表框中列出容器和blob。我无法在我的列表框中显示容器和blob 这是我要列出的代码: 最后是我调用上传、下载和列表方法的界面后面的代码: 我不清楚您遇到了什么问题,因为您没有充分解释。下面从示例中提取的代码演示了在容器中列出BLOB(包括分页支持) 单击Web表单中的Button3时看不到任何结果的原因是,您没有从ListBlob方法返回任何数据 更改ListBlob方法以返回如下结果: public List<

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

这是我要列出的代码:

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


我不清楚您遇到了什么问题,因为您没有充分解释。下面从示例中提取的代码演示了在容器中列出BLOB(包括分页支持)


单击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;
}

有例外吗?您是否在调试器中逐步完成了代码?我们通常希望您能在问题中包含代码的文本,这会使阅读和测试变得更容易。谢谢:)但是现在,当我在我的Web表单中调用该方法时,GetBlob()有问题;当前上下文中不存在名称GetBlob()!好吧,现在它工作得很好,我忘了创建我的类的对象!我做了如下操作:BlobService list=newblobservice();ListBox1.DataSource=list.ListBlob();ListBox1.DataBind();非常感谢你帮助我!当做
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;
}
protected void Button3_Click(object sender, EventArgs e)
{
    ListBox1.DataSource = GetBlobs();
    ListBox1.DataBind();
}