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

  • Home
  • SEARCH
  • 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 8570925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:40:11+00:00 2026-06-11T18:40:11+00:00

I created one pdf document var document = new Document(); string path = Server.MapPath(AttachementToMail);

  • 0

I created one pdf document

        var document = new Document();
        string path = Server.MapPath("AttachementToMail");
        PdfWriter.GetInstance(document, new FileStream(path + 
                  "/"+DateTime.Now.ToShortDateString()+".pdf", FileMode.Create));

Now I want to download this document

 Response.ContentType = "Application/pdf";
 Response.AppendHeader("Content-Disposition", "attachment; filename="+   
                                DateTime.Now.ToShortDateString() + ".pdf" + "");
 Response.TransmitFile(path);
 Response.End();

but it gave me error
Access to the path ‘~\AttachementToMail’ is denied.

read / write access for IIS_IUSRS exists

  • 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-06-11T18:40:12+00:00Added an answer on June 11, 2026 at 6:40 pm

    The path you are providing to write is a virtual path. TransmitFile expects an absolute path.

    Your code should look something like this:

    var document = new Document();
    string path = Server.MapPath("AttachementToMail");
    var fileName =  DateTime.Now.ToString("yyyyMMdd")+".pdf";
    var fullPath = path + "\\" + fileName;
    
    //Write it to disk
    PdfWriter.GetInstance(document, new FileStream(fullPath, FileMode.Create));
    
    //Send it to output
    Response.ContentType = "Application/pdf";
    Response.AppendHeader("Content-Disposition", "attachment; filename="+ fileName );
    
    Response.TransmitFile(fullPath);
    Response.Flush();
    Response.End();
    

    DateTime.Now represents the current time. Be careful when you use it as the file name.
    Using ToShortDateString is a little risky, as some cultures put / in that format. Using ToString will allow you to fix your filename format regardless of the server culture.

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

Sidebar

Related Questions

public FileResult Download() { var doc = new EO.Pdf.PdfDocument(); EO.Pdf.HtmlToPdf.ConvertUrl(http://www.google.com/, doc); var ms =
I created one linear layout and I have added two relative layout. I wish
I created one app for database which contains a student table and 3 fields
I created one accordion menu, issue is I am using .next on li but
I created one GWT webapplication project.Inthat i want to create servlet program,but in that
I created one application to read all the contacts stored in android 2.0 emulator.I
I created one application, its working fine. I want to support my application in
i created one grid view application, it's working fine now showing all images in
I created one Linear layout inside scroll view (Horizontal) in xml with number of
I have one created one folder called MYFOLDER inside my folder in have one

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.