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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:27:54+00:00 2026-05-31T01:27:54+00:00

I have read some past posts here on how to download a Excel file

  • 0

I have read some past posts here on how to download a Excel file from a website. So, I have setup the below code:

string path = MapPath(fname);
string name = Path.GetFileName(path);
string ext = Path.GetExtension(path);
string type = "application/vnd.ms-excel";


if (forceDownload)
{
    Response.AppendHeader("content-disposition",
        "attachment; filename=" + name);
}

if (type != "")
{
    Response.ContentType = type;
    Response.WriteFile(path);
    Response.End();
}

However, I get no download dialog box.

I try this both in IE 8 and FireFox 10.0.2.
The file is there, it’s not locked, and it’s not set to read only.
I’m not sure were I went wrong.

  • 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-31T01:27:55+00:00Added an answer on May 31, 2026 at 1:27 am

    According to this link, you need to add this line:

    strFileName = Path.GetFileName(path);
    Response.TransmitFile( Server.MapPath(strFileName) );
    

    This will cause a Open / Save As dialog box to pop up with the filename of SailBig.jpg as the default filename preset.

    This of course assumes you’re feeding a file that already exists. If you need to feed dynamically generated – say an image [or any file] that was generated in memory – you can use Response.BinaryWrite() to stream a byte array or write the output directly in Response.OutputStream.

    EDIT:

    Microsoft’s MSDN site has a detailed explanation about File Downloading. It includes both samples for Java and .Net applications, the concept is the same:

    1. Get the response.
    2. With the response:
      1. Set the content type to “APPLICATION/OCTET-STREAM” (it means there’s no application to open the file).
      2. Set the header to “Content-Disposition”, “attachment; filename=\”” + + “\””.
      3. Write the file content into the response.
    3. Close the response.

    So, looking at the MSDN ASP.Net file download, you’re lacking the 2.3 step. You’re just writing the file name to the response.

    // transfer the file byte-by-byte to the response object
    System.IO.FileInfo fileToDownload = new
        System.IO.FileInfo("C:\\downloadJSP\\DownloadConv\\myFile.txt");
    Response.Flush();
    Response.WriteFile(fileToDownload.FullName);
    

    With this example you will download your file successfully, of course if you can get the file with no problems :).

    EDIT 2:

    The HTML component used to download any file must be a regular HTML Request. Any ajax request to download a file won’t work. Microsoft explains that here. And the main quote:

    Its impossible to attach an event before and after a download through javascript. Browser doesn’t allow this type of events for security reasons.

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

Sidebar

Related Questions

I have read some posts on here about not mixing parameters when passing into
I have read some posts about this topic and the answers are comet, reverse
I have just switched from svn to mercurial and have read some tutorials about
I have read in some of the ClickOnce posts that ClickOnce does not allow
I have read from some article that say's Apple doesn't approve the application which
I have to create an app that will read in some info from a
i have looked into the past topics and read some questions relative of this
I have read some articles on POCO in the enttity framework but still don't
I just got Delphi 2009 and have previously read some articles about modifications that
I am new to ASP.net MVC architecture. I have read in some articles that

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.