How to Open a PDF file in a web application
I was surfing the web, and I found a site that opens a PDF file in a new page, so I thought I'll share the method of how to that with everyone :)
In the main page add this line:
{
Response.Write("<script>window.open('frmReport.asp x?r=frmReport.aspx,'_new');</script>");
}
Where frmReport.aspx is the name of the form in which you will open the file and frmReport.aspx is the name of the file, which of course you can read dynamically.
Now in the frmReport.aspx ad the following code in the Page_Load.
protected void Page_Load(object sender, EventArgs e)
{
string strFileName = Request.QueryString["r"];
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/PDF";
Response.WriteFile(strFileName);
Response.Flush();
Response.Close();
Session.Remove("Report");
}
Notice that the name of the file is sent through the URL.
Hope this will help someone in need :p
Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
__________________
Nothing is impossible. The impossible only takes longer. \"Digital Fortress, Dan Brown\"
|