2013-02-15 68 views
0

我試圖從我的Web服務下載文件(.txt)。我的網絡服務使用此代碼C#ASPX從本地主機下載文件

WebClient req = new WebClient(); 
HttpResponse Response = HttpContext.Current.Response; 

Response.ContentType = "image/jpeg"; 
Response.AddHeader("Content-Disposition", "attachment;filename=" + 
    fileName); 
Response.WriteFile("C:\\Temp\\Storage\\" + (fileName)); 
Response.End(); 

我想從客戶端調用它。這是如何完成的?

+0

您是否嘗試過使用[WebClient.DownloadFile()](http://msdn.microsoft.com/en-us/ library/ez801hhe.aspx)方法,如果是這樣,問題是什麼? – 2013-02-15 10:05:59

回答

0
private void btnDownload_Click(object sender, EventArgs e) 
{ 
    WebClient webClient = new WebClient(); 
    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); 
    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); 
    webClient.DownloadFileAsync(new Uri("http://NikUser.com/myfile.txt"), @"c:\myfile.txt"); 
} 

試試吧....希望它會工作...