To open PDF i have mentioned two methods as below,
1. Process[] processes = System.Diagnostics.Process.GetProcessesByName("AcroRd32");
foreach (Process p in processes)
{
p.Kill();
p.Refresh();
}
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Process.Start(strPDFPath);
2. System.Net.WebClient client = new System.Net.WebClient();
Byte[] buffer = client.DownloadData(strPDFPath);
Session["BUFFER"] = buffer;
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "PDF", "window.open('../pdf.aspx','_blank');", true);
In "pdf.aspx.cs" file use this code
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["BUFFER"] != null)
{
byte[] buffer = (Byte[])Session["BUFFER"];
if (buffer != null)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.AddHeader("Content-Type", "application/pdf");
Response.BinaryWrite(buffer);
Response.End();
}
}
}
catch (Exception)
{
}
}
No comments:
Post a Comment