C# 使用response.write打开byte[]pdf文件(服务器端操作不起作用

C# 使用response.write打开byte[]pdf文件(服务器端操作不起作用,c#,asp.net,response,C#,Asp.net,Response,我正在使用以下代码打开pdf byte[]文件而不保存它。它工作正常,但在此操作之后,没有其他服务器端操作(如“按钮单击”)不起作用。回发不起作用 byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim())); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.Content

我正在使用以下代码打开pdf byte[]文件而不保存它。它工作正常,但在此操作之后,没有其他服务器端操作(如“按钮单击”)不起作用。回发不起作用

    byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim()));
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment;filename="+filename);
    Response.AddHeader("Content-Length", bytfile.Length.ToString());
    Response.OutputStream.Write(bytfile, 0, bytfile.Length);
    Response.Flush();
    Response.End();

试试这个,应该有用的

byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim()));
Response.Clear();
MemoryStream ms = new MemoryStream(bytfile);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=test.pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
Response.End();
否则试试

Response.BinaryWrite(bytfile);
而不是

ms.WriteTo(Response.OutputStream);

在上面的代码中。

试试这个。它应该可以工作

byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim()));
Response.Clear();
MemoryStream ms = new MemoryStream(bytfile);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=test.pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
Response.End();
否则试试

Response.BinaryWrite(bytfile);
而不是

ms.WriteTo(Response.OutputStream);
在上面的代码中

它工作正常,但在此操作之后,没有其他服务器端操作 像按钮一样,单击按钮不起作用

    byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim()));
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment;filename="+filename);
    Response.AddHeader("Content-Length", bytfile.Length.ToString());
    Response.OutputStream.Write(bytfile, 0, bytfile.Length);
    Response.Flush();
    Response.End();
您是在页面还是控件中使用代码

请使用通用处理程序*.ashx。下载pdf的代码不会再给应用程序带来麻烦

也许可以作为参考

它工作正常,但在此操作之后,没有其他服务器端操作 像按钮一样,单击按钮不起作用

    byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim()));
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment;filename="+filename);
    Response.AddHeader("Content-Length", bytfile.Length.ToString());
    Response.OutputStream.Write(bytfile, 0, bytfile.Length);
    Response.Flush();
    Response.End();
您是在页面还是控件中使用代码

请使用通用处理程序*.ashx。下载pdf的代码不会再给应用程序带来麻烦


可能有用作参考。

还是同一个问题。你有没有其他办法来解决这个问题。@Nathiya是你在UpdatePanel触发器中使用的按钮?还是同一个问题。你有没有其他办法来解决这个问题。@Nathiya是你在UpdatePanel触发器中使用的按钮?我在页面中使用它尝试在我使用的标题中使用通用处理程序它会在页面中尝试使用通用处理程序