I want to open pdf file in new tab and visualize it.

This is my code :

SPLinkButton linkHelp = new SPLinkButton();
linkHelp.Text = "HELP...";
linkHelp.Target = "_blank";
linkHelp.Click += new EventHandler(linkHelp_Click);

This is my button event:

void linkHelp_Click(object sender, EventArgs e)
   string path = @"http://sf-spsdev02/TestSite/Shared%20Documents/UserGiude-WayBill.pdf";
   WebClient client = new WebClient();
   Byte[] buffer = client.DownloadData(path);
   if (buffer != null)
       HttpContext.Current.Response.ContentType = "application/pdf";
       HttpContext.Current.Response.AddHeader("content-length", buffer.Length.ToString());

This is a error:

enter image description here

With hyperLink This code download the file(with IE)... I want Open a file in new tab... this is possible with IE Edge.., How to do this with IE ?

HyperLink href = new HyperLink();
    href.NavigateUrl = "http://sf-spsdev02/TestSite/Shared%20Documents/UserGiude-WayBill%20System.pdf";
    href.Text = "Помощ...";
    href.Target = "_blank";
  • You can change the setting for document library to open document in browser.
    – Hardik
    Commented May 25, 2016 at 13:57
  • From where do this?
    – Goshky
    Commented May 25, 2016 at 14:00
  • Please check here...technet.microsoft.com/en-us/library/…
    – Hardik
    Commented May 25, 2016 at 14:05
  • is that works for you?
    – Hardik
    Commented May 25, 2016 at 14:24
  • Have you got the solution? is my answer helps you?
    – Hardik
    Commented May 26, 2016 at 12:35

1 Answer 1


Why you are using SPLinkButton?

You can simply use HyperLink with its attribute called Navigateurl from your code.

You can follow below steps in below mentioned URL.

Open PDF files from a Document Library in a New Window

Follow this

  1. Open IIS manager (Start | Control Panel | Administrative Tools | Internet Information Services Manager).
  2. Expand the “Application Pools” node.
  3. Right click the application pool which your project is using, and then select “Properties”.
  4. Click “Identity” tab.
  5. Choose “Local System” in the Predefined dropdown list.

About how to grant permission to a file, please check these steps:

  1. Open Windows Explorer.
  2. Right click the file, and then select "Properties".
  3. Click the "Security" tab.
  4. Add "Network Service" in access list and check "Modify", "Read", and "Write" for it.

and finally

in your code add this

System.Net.WebRequest request = System.Net.HttpWebRequest.Create("http://localhost/Webservicetest1/Service.asmx/webmrthod");

request.UseDefaultCredentials = true;
request.PreAuthenticate = true;
request.Credentials = CredentialCache.DefaultCredentials;

System.Net.WebResponse response = request.GetResponse();

Remember that below lines are important for you

request.PreAuthenticate = true;
request.Credentials = CredentialCache.DefaultCredentials;

It is working without any problem..

  • Add only this in your question i my code ?
    – Goshky
    Commented May 25, 2016 at 12:20
  • Updated my answer. Please check it.
    – Hardik
    Commented May 25, 2016 at 12:50
  • See my code below...
    – Goshky
    Commented May 25, 2016 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.