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

The Archive Base Latest Questions

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

In an MVC project, I have an ActionLink, which, when clicked, should take an

  • 0

In an MVC project, I have an ActionLink, which, when clicked, should take an arbitrary number of objects associated with the user (supplied as a List), dynamically build a CSV file of the objects’ attributes and prompt a download. The file shouldn’t persist on the server, so it either needs to be removed after download or the download needs to come from a stream or similar. What’s the neatest way of going about this? I’ve seen examples of this which manually compile a CSV string and use HttpResponse.Write(String) within the controller, but is this best practice?

  • 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:31:10+00:00Added an answer on May 27, 2026 at 3:31 pm

    I have a function that is similar to this. I’m sure there is a “better” way to automatically find each of the members of the User object you pass it, but this way works.

        public ActionResult ExportCSV(List<User> input)
        {
            using (MemoryStream output = new MemoryStream())
            {
                using (StreamWriter writer = new StreamWriter(output, Encoding.UTF8))
                {
                    foreach (User user in input)
                    {
                        writer.Write(user.firstattribute);
                        writer.Write(",");
                        writer.Write(user.secondattribute);
                        writer.Write(",");
                        writer.Write(user.thirdattribute);
                        writer.Write(",");
                        writer.Write(user.lastattribute);
                        writer.WriteLine();
                    }
    
                    writer.Flush();
                }
    
                output.Position = 0;
    
                return Controller.File(output, "text/comma-separated-values", "report.csv");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started a new mvc project and clicked on project\properties\web - use local
In my mvc project i have a simple list of items with crud operations
I am working on an ASP.NET MVC Project and I have a number of
Net MVC 3.0 Project I have a form in my page and a Ajax.ActionLink
I have a new MVC project which uses the entity framework. I'm spitting out
I have an upload function in an MVC 3 project which store the files
My first MVC project and have ran into an issue which I hope someone
In my MVC project I have a chart being generated on my view as
In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated
I have ASP.Net MVC project. Plus wordpress blog under a subfolder /Blog. Now, when

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.