How to connect Azure Storage to read .txt files from blob storage
Could anyone let me know how to read a text file from Azure 开发者_JAVA百科Blob Storage?
It's pretty easy:
string text = CloudStorageAccount.Parse("<your connection string>").CreateCloudBlobClient().GetBlobReference("path/to/the/blob.txt").DownloadText();
Of course, if the blob is in a public container, you can just do:
string text = new WebClient().DownloadString("http://youraccount.blob.core.windows.net/path/to/blob.txt");
// 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();
精彩评论