webclient.downloadfile没有完全保存页面

时间:2013-03-08 06:09:02

标签: c# .net webclient webclient-download

我使用以下代码在我的C#应用​​中保存网页,但页面未完全保存:

WebClient webClient = new WebClient();
webClient.DownloadFile("http://jahanesanat.ir/currency.html", @"d://test/mytest66.html");

页面的某些部分未保存在本地文件中 出了什么问题?

1 个答案:

答案 0 :(得分:0)

也许d:// test /被拒绝访问

使用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)