Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:47:33+00:00 2026-05-26T04:47:33+00:00

I have a requirement to generate a pdf document on a button click on

  • 0

I have a requirement to generate a pdf document on a button click on using visual web part- sharepoint 2010.
I am using the the open source library http://www.itextpdf.com/ for the same. I am able to execute the below code using the project type as a Windowns Application. But, when I want do it on a button click , I am receiving c:\windows\system32\inetsrv\Test.pdf’ is denied. error.

Below is the code that I am using

 public static void Main(string[] args)  --Console Application
    {
        Console.WriteLine("PDF demo");
        Document myDoc = new Document(PageSize.A4.Rotate());
        try
        {
            PdfWriter.GetInstance(myDoc, new FileStream("Salman.pdf", FileMode.Create));
            myDoc.Open();
            myDoc.Add(new Paragraph("First pdf File made by Salman using Itext"));
        }
        catch (DocumentException ex)
        {
            Console.Error.WriteLine(ex.Message);
        }
        myDoc.Close();
    }
}

But I want do the same on a button click event.

    protected void pdfGenerator_OnClick(object sender, EventArgs e)
    {
        Document myDoc = new Document(PageSize.A4.Rotate());
        try
        {
            PdfWriter.GetInstance(myDoc, new FileStream("Salman.pdf", FileMode.Create));---I get an error here
            myDoc.Open();
            myDoc.Add(new Paragraph("First pdf File made by Salman using Itext"));
        }
        catch (DocumentException ex)
        {
            Console.Error.WriteLine(ex.Message);
        }
        myDoc.Close();
    }
}

Please help me , i dont understand the reason for the error. I am tyring it for the first time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:47:33+00:00Added an answer on May 26, 2026 at 4:47 am

    The problem is you are trying to create a PDF in a directory you do not have access to. This is because you are not specifying the directory to save the path; which causes it to default in the same location as the current working directory. In many cases, such as for ASP.NET; the default is the same as the location of the process. For ASP.NET, the process is w3wp.exe and resides in c:\windows\system32\inetsrv. Most identities that w3wp will run as (Network Service or AppPoolIdentity) do not have access to that directory. In fact, only system administrators do.

    You need to save it somewhere else that the process has write permissions to here:

    PdfWriter.GetInstance(myDoc, new FileStream("Janaki.pdf", FileMode.Create))
    

    Should be something like:

    PdfWriter.GetInstance(myDoc, new FileStream(@"C:\directoryIcanWriteTo\Janaki.pdf", FileMode.Create))
    

    If you want to save it in the same place as the website, you would use HttpContext.Current.Server.MapPath:

        PdfWriter.GetInstance(myDoc, new FileStream(HttpContext.Current.Server.MapPath("~/Janaki.pdf", FileMode.Create))
    

    Regardless, the identity will still need write permissions to the directory if it doesn’t have them. But you definitely shouldn’t put them in inetsrv.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a requirement to generate PDF documents using information from a PDA /
I have a particular requirement to generate a PDF document with some dynamic data
I have requirement of specifying web part connections in onet.xml. So when site is
I have a requirement to dynamically generate and compress large batches of PDF files.
I have been using fop 0.95 to generate pdf files from xml data. I
I have a requirement to put together an application which will generate a web
I have a requirement where a web service is called to generate the next
I have the following requirement: Based on some user input, I need to generate
I have a requirement to display dynamically generated word document on the server in
We have a requirement to increase the functionality of a grid we are using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.