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.42k
    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(), "", "'" + 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()); 

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

 0 Comment(s)

Sign In

Sign up using

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: