1
發送文件時,我得到這個錯誤,當我嘗試從我的asp.net頁面發送一個文件:像錯誤獲取腳本asp.net
微軟JScript運行時錯誤:Sys.WebForms.PageRequestManagerParserErrorException:消息從服務器收到的無法解析。
我的代碼:
//此獲得由linkButton
網格上
protected void Download(object sender, EventArgs e)
{
LinkButton lb = sender as LinkButton;
// save file to temp
Byte[] fileBytes = null;
using (var db = new DbContext())
{
var id = Convert.ToInt32(lb.CommandArgument);
fileBytes = db.Requests.Single(x => x.Id == id).File;
}
var filePath = Path.GetTempFileName();
File.WriteAllBytes(filePath, fileBytes);
// send
FileInfo fi = new FileInfo(filePath);
SendFile(fi);
}
private void SendFile(FileInfo file)
{
Response.ContentType = "application/zip";
Response.WriteFile(file.FullName);
Response.End();
// I also tried the code below I get the same error.
//Response.Clear();
//Response.ClearHeaders();
//Response.ClearContent();
//Response.AddHeader("Content-Disposition", "attachment; filename=PriceFile.zip");
//Response.AddHeader("Content-Length", file.Length.ToString());
//Response.ContentType = "application/zip";
//Response.Flush();
//Response.TransmitFile(file.FullName);
//Response.End();
}
謝謝,我想你必須有相同的問題才能知道我在更新面板中使用它。 – sprocket12
也有在asp.net論壇上回答這些問題。 –