如何连接Azure存储以从blob存储中读取.txt文件

时间:2010-11-11 05:33:50

标签: windows azure cloud

有人能告诉我如何从Azure Blob存储中读取文本文件吗?

2 个答案:

答案 0 :(得分:15)

这很简单:

string text = CloudStorageAccount.Parse("<your connection string>").CreateCloudBlobClient().GetBlobReference("path/to/the/blob.txt").DownloadText();

当然,如果blob位于公共容器中,您可以这样做:

string text = new WebClient().DownloadString("http://youraccount.blob.core.windows.net/path/to/blob.txt");

答案 1 :(得分:2)

// connect to development storage. To connect to azure storage use connection string
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobClient client = storageAccount.CreateCloudBlobClient();

// if you know the blob you want to access you can do this:
CloudBlob blob = client.GetBlobReference("containername/blobname.txt");

// To display text in console:
Console.WriteLine(blob.DownloadText());
Console.ReadKey();