How to connect Azure Storage to read .txt files from blob storage

雨燕双飞 提交于 2019-12-10 06:39:43

问题


Could anyone let me know how to read a text file from Azure Blob Storage?


回答1:


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");



回答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();


来源:https://stackoverflow.com/questions/4151626/how-to-connect-azure-storage-to-read-txt-files-from-blob-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!