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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:30:57+00:00 2026-05-28T01:30:57+00:00

I am able to save a single value into excel but I need help

  • 0

I am able to save a single value into excel but I need help to save a full list/array into an excel sheet.

Code I have so far:

var MovieNames = session.Query<Movie>()
                          .ToArray();

List<string> MovieList = new List<string>();

foreach (var movie in MovieNames)
 {                   
  MovieList.Add(movie.MovieName);               
 }

//If I want to print a single value or a string, 
//I can use the following to print/save to excel
// How can I do this if I want to print that entire
//list thats generated in "MovieList" 

return File(new System.Text.UTF8Encoding().GetBytes(MovieList), "text/csv", "demo.csv");
  • 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-28T01:30:57+00:00Added an answer on May 28, 2026 at 1:30 am

    If you mean you want to create a .csv file with all movie names in one column so you can open it in Excel then simply loop over it:

    byte[] content;
    
    using (var ms = new MemoryStream())
    {
        using (var writer = new StreamWriter(ms))
        {
            foreach (var movieName in MovieList)
                writer.WriteLine(movieName);
        }
    
        content = ms.ToArray();
    }
    
    return File(content, "text/csv", "demo.csv");
    

    Edit

    You can add more columns and get fancier with your output but then you run into the problem that you have check for special characters which need escaping (like , and "). If you want to do more than just a simple output then I suggest you follow @Darins suggestion and use the FileHelpers utilities. If you can’t or don’t want to use them then this article has an implementation of a csv writer.

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

Sidebar

Related Questions

I'm able to connect to and read an excel file no problem. But when
I have a feeling this is not an easy task but I need to
I wonder if there is a plugin that is able to save the current
I created a DTS package. Someone else wants to be able to save it
If I open a doc in read only mode I'm able to press save
I would like to be able to fetch a web page's html and save
I want to save my program's DataModel objects to a file, and be able
Application able to record error in OnError, but we are not able to do
I'm afraid no amount of Googling has been able to save my hyde on
Suppose I have a simple to-do list application. The application contains two models: lists

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.