2013-11-25 67 views
-2

我有一個WPF應用程序。我從XML文件加載一些數據。使用File.ReadAllText不支持給定路徑的格式

我收到一個錯誤:

System.NotSupportedException was unhandled 
Message: The given path's format is not supported. 

在這條線:

string html = File.ReadAllText(Advertisement.DescriptionUrl); 

在XML這是網址:

http://mysitetest.com/x/x/Assets/shop/shopdetails/Coffee/image.png 

任何想法如何解決呢?

+0

請人添加評論時,下投票感謝 – GibboK

+1

如果我們讓事實File.ReadAllText不處理的URL,'image.png'是幾乎不會成爲一個文本文件,所以閱讀文本可能不會是你想要的。 –

回答

2

File.ReadAllText是爲了在文件系統上使用文件名而不是URL。

你需要像WebClient.DownloadString東西來取,

string text; 
using (WebClient client = new WebClient()) 
{ 
    text = client.DownloadString(url); 
} 
// Now use text 
+0

感謝您的回答 – GibboK

1

這是一個網站的網址,而不是文件路徑。

使用WebClient對象請求資源:

string html; 
using (WebClient client = new WebClient()) { 
    html = client.DownloadString(Advertisement.DescriptionUrl); 
} 
相關問題