locked
iTextSharp Problem! RRS feed

  • Question

  • User-1438755731 posted

    Hi,

    I'm trying to use iTextSharp to convert an aspx to pdf and I get the error:

    Access to the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\Invoice.pdf' is denied.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\Invoice.pdf' is denied.

    ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

    To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

    Source Error:

    Line 85:     {
    Line 86:         Document document = new Document(PageSize.A4.Rotate());
    Line 87:         PdfWriter.GetInstance(document, new FileStream("Invoice.pdf", FileMode.Create));
    Line 88:         document.Open();
    Line 89: 


    I've tried giving full control as stated in the error message to the IUSR user in the machine config security tab but its not working! 

    Any Tips?

    Wednesday, December 8, 2010 11:44 AM

Answers

  • User1508394307 posted

    You should set correct path for the output file. For example, if you want to create a file in web root directory, use:

    PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/Invoice.pdf"), FileMode.Create));

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 8, 2010 1:14 PM

All replies

  • User1508394307 posted

    You should set correct path for the output file. For example, if you want to create a file in web root directory, use:

    PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/Invoice.pdf"), FileMode.Create));

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 8, 2010 1:14 PM
  • User-1598917946 posted

    To your C drive give read and write of the prevelige to the folder for network services

    Wednesday, December 8, 2010 1:20 PM