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 943191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:23:47+00:00 2026-05-15T22:23:47+00:00

I have a file, say a PDF on my website and when a user

  • 0

I have a file, say a PDF on my website and when a user visits a page I want to display a download dialog for the pdf on page load or a button click.

I did a google search and I found two ways to do this but wondering what is the accepted way of doing this? I am currently doing this

string pdfPath = MapPath("mypdf.pdf");
Response.ContentType = "Application/pdf";


Response.AppendHeader( "content-disposition",
        "attachment; filename=" + name );
Response.WriteFile(pdfPath);
Response.End();

(Code was based off code from http://aspalliance.com/259, also found code from
http://www.west-wind.com/weblog/posts/76293.aspx)

  • 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-15T22:23:48+00:00Added an answer on May 15, 2026 at 10:23 pm

    Your code, will display the file to the user perfectly. But they will have to use the “Save As” option to actually save it.

    If you wish to present the “Save Dialog” to the user, try the following:

    string pdfPath = MapPath("mypdf.pdf");
    Response.ContentType = "Application/pdf";
    Response.AppendHeader("content-disposition",
            "attachment; filename=" + pdfPath );
    Response.TransmitFile(pdfPath);
    Response.End();
    

    This of course assumes the file actually exists on the server and is not being dynamically generated.

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

Sidebar

Related Questions

To index my website, I have a Ruby script that in turn generates a
If I have an in-memory string in JavaScript that is let's say Excel or
I have been tinkering around with PDF::API2 and i am facing a problem, create
I'm creating a pdf file using BIRT reporting library. Later I need to digitally
I am using Gnuwin32 binaries on a Windows environment. When I want to find
I have a bugzilla install set up with English and Japanese templates to support
I have contemplating how to handle paper document input in Webapps for some time.
We are in the final preparations for releasing a product and we have to
When writing rules for access control in yii controllers, possible parameters to be set
I realize there are similar questions but only regarding saving files on Linux servers

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.