无法从azure blob容器中获取文件名

时间:2015-07-13 05:48:25

标签: azure c#-4.0

我有一个对所有人公开的天蓝色容器,我想检索该公共容器中存在的文件名。

这是我的代码。

// Retrieve storage account from connection string.
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString());

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

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(sourceurl);  //my path from where i have to get filename  

//here i got 400 bad request error.
var blobs = container.ListBlobs(null, true, BlobListingDetails.All).Cast<CloudBlockBlob>().ToList();   
foreach (var blockBlob in blobs)
{
    Console.WriteLine("Name: " + blockBlob.Name);
    Console.WriteLine("Size: " + blockBlob.Properties.Length);
    Console.WriteLine("Content type: " + blockBlob.Properties.ContentType);
    Console.WriteLine("Download location: " + blockBlob.Uri);
    Console.WriteLine("=======================================");
} 

1 个答案:

答案 0 :(得分:0)

根据您的评论,请将您的代码更改为以下内容:

CloudBlobContainer container = blobClient.GetContainerReference("vcmobilesiteiislogs");
var blobs = container.ListBlobs("VCMOBILESITE/2015/07/10/10/", true, BlobListingDetails.All).Cast<CloudBlockBlob>().ToList();  

基本上vcmobilesiteiislogs是你的容器,你想要获取以VCMOBILESITE/2015/07/10/10/开头的blob名称(或者换句话说在该子文件夹中,但我必须声明blob存储没有概念您只需通过在blob前添加一些您想用作文件夹名称的名称来创建文件夹层次结构的错觉。

因此,当您在容器上调用ListBlobs方法时,您会将VCMOBILESITE/2015/07/10/10/作为blob前缀传递。