我想下載按鈕或鏈接點擊xml文件,因爲我在網頁表單中使用Gridview時點擊按鈕或鏈接它會打開新標籤上的XML文件,因爲我想下載它。我現在用的HTTP URL(如:http://SomeName/XmlFiles/1554263.xml)如何從網址下載xml文件
0
A
回答
0
這可能做的伎倆爲您
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.DownloadFile("http://SomeName/XmlFiles/1554263.xml", "some.xml");
}
WebClient.DownloadFile下載從URI通過在地址參數中指定一個本地文件數據。此方法阻止下載資源。要下載資源並在等待服務器響應時繼續執行,請使用其中一種DownloadFileAsync方法。
編輯
SaveFileDialog savefile = new SaveFileDialog();
// set a default file name
savefile.FileName = "unknown.xml";
if (savefile.ShowDialog() == DialogResult.OK)
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.DownloadFile("http://SomeName/XmlFiles/1554263.xml", savefile.FileName);
}
}
+0
我已經試過這個,但我需要將它保存在用戶提供的特定路徑上,所以我想要一個保存對話框並下載該路徑,我該如何實現。 –
+0
如何打開此文件的保存對話框下載 –
+0
其不工作,可能是因爲保存對話框是winform的屬性 –
0
這可以幫助你。
using System.Net;
string xyzstring;
try
{
WebClient wc = new WebClient();
xyzstring= wc.DownloadString("http://www.example.com/somefile.xml");
}
catch (WebException ex)
{
MessageBox.Show(ex.ToString());
}
相關問題
- 1. 如何從網址下載.txt文件?
- 2. 從網址下載XML
- 3. 從網址下載zip文件
- 4. 從gwt網址下載文件
- 5. 從cdn網址下載圖片文件
- 6. 從網址下載未知文件
- 7. 抓取:從網址下載文件
- 8. 從網址下載批文件
- 9. Android - 從網址下載JSON文件
- 10. 下載文件從短網址
- 11. 從網址下載pdf文件名PHP
- 12. 從網址中使用winhttp下載xml文件 - CHARSET = UTF-8
- 13. 如何從XML文件下載圖像?
- 14. 如何通過ssh從網址下載文件到服務器
- 15. 如何從外部網址下載文件到變量?
- 16. 如何從下載文件中刪除網址
- 17. 如何從特定網址下載文件?
- 18. 如何從多個網址下載多個文件NSOperationQueue
- 19. 如何從網址下載所有文件?
- 20. 如何抓取並從動態網址下載文件?
- 21. 如何將圖像從網址下載到繪圖文件夾?
- 22. 科爾多瓦:從網址下載到Android下載文件夾
- 23. 如何從網址下載圖片?
- 24. SILVERLIGHT。如何從網站下載文件
- 25. 如何從網頁下載文件?
- 26. 如何從C#網站下載文件?
- 27. 如何從網站下載.cs文件?
- 28. 如何從網站下載文件?
- 29. 從FTP下載xml文件
- 30. 從網址下載文件,並驗證文件已被完全下載
或者,如果重複是不夠的 - http://stackoverflow.com/questions/17034396/downloading-xml-file-from-a-url-using-c-sharp顯示保存結果文件.. (顯然你自己已經完成了這項研究,但是由於某種原因,沒有把你的調查結果投入到這篇文章中 - 對於未來的問題,一定要在問題中提供這些信息,否則後期研究可能會由於缺乏*實證研究而被低估*) –