所以我有一個頁面,我動態地生成一個表和鏈接按鈕都在一個大的UpdatePanel內。點擊每個鏈接按鈕將導致調用此方法。目標是將鏈接指向我的數據庫中的文件,並在單擊時允許用戶打開/保存爲該文件。這種確切的方法在我的網站的另一個頁面上正常工作,但通常情況下設置相同,但出現在這一個上:ASP.NET程序文件下載
Microsoft JScript運行時錯誤:Sys.WebForms.PageRequestManagerParserErrorException:無法解析從服務器收到的消息。此錯誤的常見原因是,通過調用Response.Write(),響應篩選器,HttpModules或服務器跟蹤已啓用來修改響應時。 詳細信息:分析'%PDF-1.3'附近的錯誤 % 1 0 ob'。
public void downloadFile(int fileID)
{
using (SurveyDataContext context = new SurveyDataContext())
{
try
{
var file = context.tblFiles.Single(f => f.FileID == fileID);
Response.Clear();
Response.Buffer = true;
Response.BufferOutput = true;
Response.ContentType = file.MIMEtype;
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + file.FileName.Trim() + "\"");
Response.AddHeader("Extension", file.FileName.Substring(
file.FileName.LastIndexOf('.') + 1).ToLower());
Response.BinaryWrite(file.FileData.ToArray());
Response.Flush();
Response.End();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.InnerException);
}
}
}
我在做什麼錯?我沒有做任何Response.Writes或任何東西。這種方法是唯一觸及Response的方法。有沒有其他方式我應該這樣做?
我嘗試添加Response.Flush,並沒有幫助。我沒有看到我的代碼和示例之間的區別除了我使用Response.BinaryWrite和他們使用Response.FileWrite但我沒有在文件系統上的文件,因此FileWrite將無法正常工作。 – jamone 2010-02-01 17:04:38