简体   繁体   English

不支持streamreader异常URI格式

[英]streamreader exception URI formats are not supported

I am using azure blob storage . 我正在使用azure blob storage I stored an txt file in the storage, and now i am trying to read it through : 我在存储中存储了一个txt文件,现在我正尝试通过以下方式读取它:

StreamReader reader = new StreamReader(Blob.Uri.AbsoluteUri); 
Blob containes the reference of the blob where txt file is stored.

But here i am getting the exception (URI formats are not supported.) . 但是在这里,我遇到了异常(URI formats are not supported.) I think the streamreader does'nt support the URI formate. 我认为流streamreader不支持URI streamreader Can anybody please give me a better work arround for this ? 有人可以为此给我更好的工作吗?

( i know one that we can use DowmloadToFile method of CloudBlob to download the file and then create an address by using Server.MapPath and put that address instead of URI. But if there is any other better solution for this then please let me know ) (我知道有一个,我们可以用DowmloadToFile的方法CloudBlob下载的文件,然后使用创建使用Server.Mappath一个地址,并把该地址,而不是URI。但是,如果有其他更好的解决方案为这个,那么请让我知道)

Take a look at WebClient.OpenRead or WebClient.DownloadString methods. 看一下WebClient.OpenReadWebClient.DownloadString方法。

Your code will looks like something like that : 您的代码看起来像这样:

var wc = new WebClient();
using(var sourceStream = wc.OpenRead(Blob.Uri.AbsoluteUri)){
    using(var reader = new StreamReader(sourceStream)){
         // Process
    }
}

Or if the file is small (text files are often small), : 或者,如果文件很小(文本文件通常很小),则:

var wc = new WebClient();
var fileContent = wc.DownloadString(Blob.Uri.AbsoluteUri);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM