【发布时间】:2016-03-14 06:12:17
【问题描述】:
直接来自 MSDN 教程:
string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder.
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);
有没有一种简单的方法可以下载文件夹及其子文件夹及其文件?我知道如何使用 dos 来执行此操作,但是您如何在 C# 中执行此操作?一定有一个简单的公式。
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://www.website.com/tools/update/*.*", @"c:\downloads");
有点喜欢做:
xcopy source destination /E
但来自网络目录
【问题讨论】: