Display (Open) PDF File in new Window using C# in ASP.Net

Hazel
 
on Aug 25, 2021 08:49 AM
469 Views

I have below code. How do I open the pdf file in new window?

Please help. TQ in advance.

// utk file di server
string filePath = Server.MapPath("~/isoChecklist/" + (sender as ImageButton).CommandArgument); 
Response.TransmitFile(Server.MapPath(filePath)); 
FileInfo file = new FileInfo(filePath); 
// Checking if file exists
if (file.Exists)
{
    // Clear the content of the response
    Response.ClearContent(); 
    // LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
    Response.AddHeader("Content-Disposition", "inline; filename=" + file.Name); 
    // Add the file size into the response header
    Response.AddHeader("Content-Length", file.Length.ToString()); 
    // Set the ContentType
    Response.ContentType = ReturnExtension(file.Extension.ToLower());      
    Response.TransmitFile(file.FullName); 
    Response.End();
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Andrea
 
on Aug 25, 2021 08:49 AM
Hi @Hazel,
Please try the following

Open PDF File in New Window or New Tab on Button click in ASP.Net

It might help you.

Cheers Andrea.