• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1106
  • Last Modified:

Opening a PDF in ASP.net site deployed to server

Hi, I have an asp.net that creates a pdf file and saves it to the c drive. Once it has been saved I would like the pdf document top open for the user. When creating the site in visual studio i used 'System.Diagnostics.Process.Start(path2)' which worked perfectly.

Now I have deployed to a serer and Process.Start doesnt work. I think it may be something to do with permissions but i'm not sure where to look. Could somebody advise?

Alternatively I have tried the code below, this works great but it opens the document in the current window. Is there a method of opening the docuemnt in a new browser window?:

 Response.ContentType = "application/pdf"
        Response.Clear()
        Response.TransmitFile(path2)
        Response.End()

Thanks
0
BWA IT
Asked:
BWA IT
  • 4
  • 3
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
u can try this:
Response.Write("<script>");
Response.Write("window.open('" + path2 + "', '_newtab');");
Response.Write("</script>");

Open in new window


or try this with Process.Start:
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = path2;
process.Start();

Open in new window

0
 
BWA ITAuthor Commented:
I tried the Process.Start method but I get the same problem, the pdf is created but doesnt open.

I tried the Response.Write method but get the error message "Microsoft JScript runtime error: Access is denied." Do you know what that could be?

Thanks
0
 
Meir RivkinFull stack Software EngineerCommented:
cam u make sure the path to the pdf file is correct?
it should be url to the pdf location not physical path of the file.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
BWA ITAuthor Commented:
Thanks at the moment the pdf is saved to the c drive (using Console.WriteLine) so variable path2 = "C:/newpdf.pdf". How would I change this to a url?
0
 
Meir RivkinFull stack Software EngineerCommented:
the pdf should be under the directory where your web site is mapped to.
for example when you navigate to the web site, you use http://www.mywebsite.com/index.html
in the background its mapped to the physical directory in the server where index.html resides.
so what u want to do is place the pdf file somewhere under the web site physical path and then u can pass the url relative to the pdf file location.
0
 
BWA ITAuthor Commented:
Thanks worked great!
0
 
Meir RivkinFull stack Software EngineerCommented:
u welcome, good luck.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now