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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:52:12+00:00 2026-05-12T11:52:12+00:00

How should I go about providing download functionality on an asp.net page to download

  • 0

How should I go about providing download functionality on an asp.net page to download a series of rows from a database table represented as a linq2sql class that only has primitive types for members (ideally into a format that can be easily read by Excel)?

E.g.

public class Customer
{
public int CustomerID;
public string FirstName;
public string LastName;
}

What I have tried so far.

Initially I created a DataTable, added all the Customer data to this table and bound it to a DataGrid, then had a download button that called DataGrid1.RenderControl to an HtmlTextWriter that was then written to the response (with content type “application/vnd.ms-excel”) and that worked fine for a small number of customers.

However, now the number of rows in this table is >10,000 and is expected to reach upwards of 100,000, so it is becoming prohibitive to display all this data on the page before the user can click the download button.

So the question is, how can I provide the ability to download all this data without having to display it all on a DataGrid first?

  • 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-12T11:52:12+00:00Added an answer on May 12, 2026 at 11:52 am

    So after a bit of research, the solution I ended up trying first was to use a slightly modified version of the code sample from http://www.asp.net/learn/videos/video-449.aspx and format each row value in my DataTable for CSV using the following code to try to avoid potentially problematic text:

    private static string FormatForCsv(object value)
            {
                var stringValue = value == null ? string.Empty : value.ToString();
                if (stringValue.Contains("\"")) { stringValue = stringValue.Replace("\"", "\"\""); }
                return "\"" + stringValue + "\"";
            }
    

    For anyone who is curious about the above, I’m basically surrounding each value in quotes and also escaping any existing quotes by making them double quotes. I.e.

    My Dog => "My Dog"
    My "Happy" Dog => "My ""Happy"" Dog"
    

    This appears to be doing the trick for now for small numbers of records. I will try it soon with the >10,000 records and see how it goes.

    Edit: This solution has worked well in production for thousands of records.

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

Sidebar

Related Questions

Are there any big differences a developer should care about?
I'm wondering that how much worried I should be about data types. I can
Two quick questions if I may, is this how I should go about taking
How should I go about creating a NavigationController for use in a view-based application?
How should I go about parsing a url in php? I wanna make it
How should I go about pushing the value of a variable to an input
I have asked What should i know about search engine crawling? Now i would
To what degree should I be worried about the following warning that is displayed
About best practices on designing stored procedures, should a stored procedure updating a record
How should I go about handling http uploads that exceeds the post_max_size in 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.