SP07 - Open a pdf file in new tab on IE
-
09-10-2020 - |
Question
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());
HttpContext.Current.Response.BinaryWrite(buffer);
}
}
This is a error:
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";
Solution
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
- Open IIS manager (Start | Control Panel | Administrative Tools | Internet Information Services Manager).
- Expand the “Application Pools” node.
- Right click the application pool which your project is using, and then select “Properties”.
- Click “Identity” tab.
- Choose “Local System” in the Predefined dropdown list.
About how to grant permission to a file, please check these steps:
- Open Windows Explorer.
- Right click the file, and then select "Properties".
- Click the "Security" tab.
- 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..
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange