[英]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.