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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:08:26+00:00 2026-06-14T14:08:26+00:00

I am trying to find a way to export data from my database and

  • 0

I am trying to find a way to export data from my database and save it as a .csv file. Ideally the user will be able to select a date range on a view, which will display the data to be exported, then the user can click an “export to CSV” link. I’ve done quite a bit of searching and but have not found much specific enough to help me step through the process. Any help would be great.

I would like to export data from this database model…

{
public class InspectionInfo
{
    [Key]
    public int InspectionId { get; set; }
    [DisplayName("Date Submitted")]
    [DataType(DataType.Date)]
    //  [Required]
    public DateTime Submitted { get; set; }
    [DataType(DataType.MultilineText)]
    [MaxLength(1000)]
    //  [Required]
    public string Comments { get; set; }




    // [Required]
    public Contact Contact { get; set; }
    [ForeignKey("Contact")]
    public Int32 ContactId { get; set; }

    [MaxLength(100)]
    public String OtherContact { get; set; }

I have a service for search also, just having difficulty implementing

public SearchResults SearchInspections(SearchRequest request)
    {
        using (var db = new InspectionEntities())
        {
            var results = db.InspectionInfos
                .Where( i=> 
                        (
                            (null == request.StartDate || i.Submitted >=   request.StartDate.Value) &&
                            (null == request.EndDate || i.Submitted <= request.EndDate.Value)
                        )

            )
            .OrderBy(i=>i.Submitted)
            .Skip(request.PageSize*request.PageIndex).Take(request.PageSize);

            return new SearchResults{
                TotalResults=results.Count(),
                PageIndex=request.PageIndex,
                Inspections=results.ToList(),
                SearchRequest=request
        };

        }
    }
  • 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-14T14:08:28+00:00Added an answer on June 14, 2026 at 2:08 pm

    You can build the CSV output in a controller action and return it directly to the browser like this:

    public ActionResult DownloadAsCsv(DateTime? start, DateTime? finish)
    {
        // I guess you would use your SearchInspections instead of the following
        // but don't understand it well enough to be sure:
    
        IEnumerable<MyRowClass> rows = GetRelevantRows(start, finish);
    
        StringBuilder csv = new StringBuilder();
        foreach (MyRowClass row in rows)
        {
            // Take care to properly escape cells with embedded " or ,
            // The following is simplified by not doing that for brevity:
            csv.Append(row.PropertyA).Append(',').Append(row.PropertyB);
            csv.AppendLine();
        }
    
        var data = Encoding.UTF8.GetBytes(csv.ToString());
        string filename = "YourDesiredFileName.csv";
        return File(data, "text/csv", filename);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find a way to export a list of file names
Trying to find a way to remove blank pages from a document I wrote
Trying to find a way to send a POST HTTPS request from Python to
I am trying to find a way to prevent the keyboard from appearing when
I'm trying to find a way to find out what file and line number
The web application I'm currently developing supports CSV export from (using SELECT INTO OUTFILE)
I am trying to find out a way to export all items in a
I am trying to find a way make 3D PCA visualization from R more
I am trying to find a way to increment a second primary key column
I am trying to find a way to reverse a string, I've seen alternatives

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.