2016-12-27 28 views
-1
到從網上下載任何文件

有什麼我試圖做的, 我想自動下載存儲在 互聯網一些特定的文件,如照片視頻圖像等 和然後存儲它們。如何使用asp.net

一些照片,我可以通過圖形界面來下載, 但我想automatication - 下載我想做的事情時,我想通過 一個非常具體的過程,我將在稍後確定。

我不希望它被下載到服務器必然,實際上 我希望客戶端提出這種請求並接收數據。

我不知道很多有關互聯網協議,它仍然是某種不明 我,但我想我應該能夠下載文件 ,我可以正常地通過Web瀏覽器訪問, 我不沒有任何想法,但如何去做。

(基本上,將文件永久保存在硬盤中)。

任何解決方案?

回答

0

使用WebClient對象下載文件以簡單的方式:

string remoteUri = "http://www.contoso.com/library/homepage/images/"; 
string fileName = "ms-banner.gif", myStringWebResource = null; 
WebClient myWebClient = new WebClient(); 
myStringWebResource = remoteUri + fileName; 
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource); 
myWebClient.DownloadFile(myStringWebResource,fileName);  
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource); 
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);