0
我編寫了一個程序,使用WebClient.DownloadFile()
從網站下載文件。下載文件錯誤
public static void downWeb()
{
WebClient myWebClient = new WebClient();
path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (add() == 1)
{
Console.WriteLine("Response is " + add());
Console.WriteLine("Downloading File = " + dynFileName + "....");
myWebClient.DownloadFile(fullAddress, (path + dynFileName));
}
}
public static int add()
{
string url = fullAddress;
WebRequest webRequest = WebRequest.Create(url);
WebResponse webResponse;
try
{
webResponse = webRequest.GetResponse();
}
catch
{
return 0;
}
return 1;
}
downWeb()
是在Main()
函數被調用的函數。
add()
是測試服務器上文件可用性的函數。如果響應是肯定的,則返回值「1」。
fullAddress =文件必須下載的地址。每次在Main()
中存在的循環中調用此函數之前都會發生變化。
當我開始我的申請,我要求用戶:網頁
1)輸入網址進行下載即www.1234.com \ samplefiles \ PG-次數1.pdf
2)數(通過更改上面的文件名編號在一個循環中,因爲其餘的url在服務器上是相同的)
現在我的問題是當我下載文件,第一次文件下載完成,但第二次下載永遠不會完成。它說「請求已計劃」,並且我的申請關閉。
我不知道這裏發生了什麼。
這怎麼解決?
在重要事件上設置斷點時,您會看到什麼行爲? –