[英]streamreader exception URI formats are not supported
我正在使用azure blob storage
。 我在存储中存储了一个txt文件,现在我正尝试通过以下方式读取它:
StreamReader reader = new StreamReader(Blob.Uri.AbsoluteUri);
Blob containes the reference of the blob where txt file is stored.
但是在这里,我遇到了异常(URI formats are not supported.)
。 我认为流streamreader
不支持URI streamreader
。 有人可以为此给我更好的工作吗?
(我知道有一个,我们可以用DowmloadToFile
的方法CloudBlob
下载的文件,然后使用创建使用Server.Mappath一个地址,并把该地址,而不是URI。但是,如果有其他更好的解决方案为这个,那么请让我知道)
看一下WebClient.OpenRead或WebClient.DownloadString方法。
您的代码看起来像这样:
var wc = new WebClient();
using(var sourceStream = wc.OpenRead(Blob.Uri.AbsoluteUri)){
using(var reader = new StreamReader(sourceStream)){
// Process
}
}
或者,如果文件很小(文本文件通常很小),则:
var wc = new WebClient();
var fileContent = wc.DownloadString(Blob.Uri.AbsoluteUri);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.