Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to open a .pdf file in a new window in C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 5.48k
    Comment on it

    Opening a .pdf file in new window

    On the First page write the following code:-

    string Url = "Wite the url of the page to be opened"; 
    ClientScript.RegisterStartupScript(this.GetType(), "", "window.open('" + Url + "');", true); 

    On the second page (the page to be opened) write this on page load

      string path = "Wite path of the pdf file to be opened"; 
        WebClient client = new WebClient();  
        Byte[] buffer = client.DownloadData(path); 
        if (buffer != null) 
        { 
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", buffer.Length.ToString()); 
            Response.BinaryWrite(buffer);
        }
    

    Note :- Please import the namespace "using System.Net" to use WebClient.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: