2013-12-18 31 views
0

我在我的應用程序中實現了Web文件管理器。它顯示來自FTP服務器的文件。 當我嘗試通過單擊文件下載文件我收到以下錯誤。 在執行WriteFile行時出現錯誤。找不到文件 - C#中的「Content-Disposition」

錯誤:

​​

//代碼:

Response.AddHeader("Content-Disposition", "attachment; filename=" + lnkName.Text.Trim()); 
    Response.WriteFile(lnkName.Text); 
    Response.End(); 

lnkName.Text.Trim文件的名稱將被設置。 例如:AdminMaster.master.cs

我在哪裏錯了?

+0

更改應用程序池,以您的用戶帳戶,然後再試一次。 – Will

+0

錯誤非常簡單 - 文件不在那裏。仔細檢查它是否真的存在,或者AppPool的身份是否有足夠的權限訪問該文件。 – nim

+1

我在嘗試下載單擊的文件。 – iamCR

回答

0

得到了一個解決方案:

//代碼

  string filename = 'Get the full path of file'; //something like /httpdocs/Images/button.gif 
      string strURL = "http://www.servername.com/"; 

      WebClient req = new WebClient(); 
      HttpResponse response = HttpContext.Current.Response; 
      response.Clear(); 
      response.ClearContent(); 
      response.ClearHeaders(); 
      response.Buffer = true; 
      response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\""); 
      byte[] data = req.DownloadData(strURL); 
      response.BinaryWrite(data); 
      response.End();