1
我正在使用鏈接按鈕從服務器下載文件。 當我使用頁面的完整路徑時,它工作正常。下載鏈接無效
下載鏈接位於默認頁面上。
即http://mydomain.com/default.aspx 但不使用http://mydomain.com/
和offcourse它在本地主機workign不是在服務器上時,工作。
我使用的代碼是
try
{
// System.String filename = this.ViewState["ImageName"].ToString();
string fileName = "filename.pdf";
// set the http content type to "APPLICATION/OCTET-STREAM
Response.ContentType = "APPLICATION/OCTET-STREAM";
// initialize the http content-disposition header to
// indicate a file attachment with the default filename
// "myFile.txt"
System.String disHeader = "Attachment; Filename=\"" + fileName +
"\"";
Response.AppendHeader("Content-Disposition", disHeader);
// transfer the file byte-by-byte to the response object
System.IO.FileInfo fileToDownload = new
System.IO.FileInfo(Server.MapPath("~/UserUploads/") + fileName);
Response.Flush();
Response.WriteFile(fileToDownload.FullName);
}
catch (System.Exception ex)
// file IO errors
{
//SupportClass.WriteStackTrace(ex, Console.Error);
throw ex;
}
}
請幫我提前來解決這個
感謝
世斌
您能否定義'not working'這個概念?你有錯誤嗎?怎麼了? – 2012-01-13 08:10:33
_Works在我的機器上:) – 2012-01-13 08:15:06
沒有錯誤即將到來。頁面jst後支持..多數民衆贊成在所有 – 2012-01-13 08:35:56