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

Display PDF file - access denied

I'm trying to pop up a PDF file that I create using itextsharp. All is fine. PDF is created and saved to a directory. But I also like
to popup the PDF. I've tried code below but nothing happens. I get the generated PDF but PDF itself doesnt open...



Document document = new Document();
 PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Server.MapPath("Chap0102.pdf"), FileMode.Create));
 document.Open();

  ....Do some stuff with the PDF here

First code:
Response.Redirect(Server.MapPath("Chap0102.pdf"));  //I get Access denied even tho i gave ASPNET rights to the folder

Second Code: //get access denied as well
 Page.ClientScript.RegisterStartupScript(this.GetType(), "pdf", "window.open(' " + Server.MapPath("Chap0102.pdf") + "');", true);


third code: nothing happens

string FilePath = MapPath(Server.MapPath("Chap0102.pdf"));
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", FilePath);
Response.WriteFile(FilePath);
Response.End();


//close the document

document.close();  //i've also tried closing the document before poping up the PDF

Open in new window

0
Camillia
Asked:
Camillia
  • 5
  • 2
1 Solution
 
CtrlAltDlCommented:
Your "third code" should work, so I'm guessing the path maybe wrong try this code and see if it is the correct path.
string FilePath = MapPath(Server.MapPath("Chap0102.pdf"));
Response.Write(FilePath);

Open in new window

0
 
CamilliaAuthor Commented:
let me try.Will post back.

0
 
CamilliaAuthor Commented:
I get an error msg, that's good. I get this msg:

'C:....\Chap0102.pdf' is not a valid virtual path.

Virtual path tho??

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CamilliaAuthor Commented:
yes, i changed it to string FilePath = "Chap0102.pdf"; (removed server.mappath) and it works now.

But i want it to open in another window...it's opening in the same window... let me try my first 2 methods without the server.mappath and see...
0
 
CamilliaAuthor Commented:
Tried this:
Response.Redirect(Server.MapPath("Chap0102.pdf"));  and removed Server.MapPath. It works but still opens it in the same browser window.
0
 
CamilliaAuthor Commented:
Yes, this works. Thanks for your idea

Page.ClientScript.RegisterStartupScript(this.GetType(), "pdf", "window.open('Chap0102.pdf');", true);
0
 
CtrlAltDlCommented:
That would have to happen client-side.
<a href="openMyPDF.aspx?pdf=Chap0102.pdf" target="_blank">My PDF</a>

Or by using javascript:
window.open(""openMyPDF.aspx?pdf=Chap0102.pdf");
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now