Abstract: browser directly open the pdf file, ask the download window does not appear
Customer demand is to directly open the pdf file in a browser, do not ask direct download or open windows again!
And we will use statements made in asp.net reporting services, for customers to turn into a pdf download.
Because of the program need to be slightly rewritten ..
The following is the practice of c # code, xxx represents the acquired data;
Suppose I have a page download.aspx, as follows, remember not to have this page iframe, otherwise you will have no effect
private void Page_Load(object sender, System.EventArgs e)
{
DataSet ds=xxxx;
if (ds.Tables[0].Rows.Count>0)
{
Response.Write(ds.Tables[0].Rows[0]["x"].ToString());
string newName=HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["x"].ToString(),System.Text.Encoding.UTF8);
Response.Clear();
//以下为原先的code
//Response.AddHeader("Content-Disposition","attachment; filename=" + newName);
/Response.ContentType="application/octet-stream";
//以下为变更后的code
Response.AddHeader("Content-Disposition","inline; filename=" + newName);
Response.ContentType="Application/PDF";
Response.AddHeader("Content-Length", (ds.Tables[0].Rows[0]["y"] as byte[]).Length.ToString());
Response.BinaryWrite(ds.Tables[0].Rows[0]["y"] as byte[]);
Response.End();
}
}
Original: Large column browser directly open the pdf file, ask the download window does not appear