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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:38:20+00:00 2026-05-27T15:38:20+00:00

Below is the offending code, I download a csv however it appends the page

  • 0

Below is the offending code, I download a csv however it appends the page source to the bottom any ideas on how to prevent this?

            var priceList = Test();
            const string downloadName = "PriceList.csv";
            var fs = new FileStream(downloadName, FileMode.Create);

            var csv = new CsvHelper.CsvHelper(fs);
            csv.Writer.WriteRecords(priceList);
            Response.ClearContent();

            //not sure what the correct content type is. This is probally wrong
            Response.ContentType = "application/xls";
            //Setting size is optional               
            Response.AddHeader("Content-Disposition",
               "attachment; filename=" + downloadName + "; size=" + fs.Length.ToString());
            var fn = fs.Name;
            fs.Close();
            loadingImage.Visible = false;
            Response.TransmitFile(fn);
            Response.Flush();
  • 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-27T15:38:20+00:00Added an answer on May 27, 2026 at 3:38 pm

    Call Response.End().

    Also, why save the file just to resend it? At best this is wasteful, but also if you’re reusing the name then you’ve a race-condition if two people hit this page at the same time. Instead of sending the file, use var csv = new CsvHelper.CsvHelper(Response.OutputStream) so you write straight to the browser (you’ll have to send your headers first though).

    Also, the content-type for CSV files is text/csv.

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

Sidebar

Related Questions

The offending block of code is below. The code almost always works, but sometimes
Below is the code of a simple html with a table layout. In FF
Below are 2 code snippets used to check if a folder exists in a
Please see my answer to this question below. It is based upon Kevin's input,
I have a Dojo-DataGrid which is programatically populated as below : var jsonStore =
A DialogViewController contains an EntryElement and RefreshRequested handler is set (see code below). Run
As you can see in the code below, I have an Abstract Base Class
I am trying to download the contents of a website. However for a certain
The code below generates different exception stack trace in both debug and release mode:
We have the below code (partial code) that is used as part of a

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.