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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:11:23+00:00 2026-05-31T06:11:23+00:00

The following code outputs the result to a csv file. Lets say there are

  • 0

The following code outputs the result to a csv file. Lets say there are 10 values in the ‘valueDataList’ … When this is run, only one row is outputted to the file. How can I loop through the code to print the file for all values ‘at once’ in “valueDataList”.

   foreach (var value in valueDataList)

    {
        var value1 = xxxxxxx    // this value is set here based on a query.. 
        int value2 = xxxxxxxx   // this value is set here based on a query.. 

        byte[] content;

        using (var ms = new MemoryStream())  
           {
              using (var writer = new StreamWriter(ms))
                {
                  writer.WriteLine("ValueHeading1   " + " ValueHeading2");
                  writer.WriteLine(value1 + "              " + value2);                         
                }
                  content = ms.ToArray();
                  return File(content, "text/csv", "demo.csv");
           }
    }   

Basically I want to be able to append to an existing csv file on each loop iteration. How can I do this? thanks for your help.

  • 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-31T06:11:24+00:00Added an answer on May 31, 2026 at 6:11 am

    Do you mean you want to write all rows from valueDataList to a csv-file?
    If so;

    using (var ms = new MemoryStream())  
    using (var writer = new StreamWriter(ms))
    {
        writer.WriteLine("ValueHeading1   " + " ValueHeading2");
    
        foreach (var value in valueDataList)
        {
            var value1 = xxxxxxx    // this value is set here based on a query.. 
            int value2 = xxxxxxxx   // this value is set here based on a query.. 
    
            writer.WriteLine(value1 + "              " + value2);                         
        }   
    
        byte[] content = ms.ToArray();
        return File(content, "text/csv", "demo.csv");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $sql = INSERT INTO table VALUES ('', ...); $result
The following code strips a ThreadState to one of the four most useful values:
The following code: $options = $value[$i]['options']; print_r($options); outputs the following result: Array ( [0]
I'm really stuck on why the following code block 1 result in output 1
The following code outputs Illegal seek: #include <stdio.h> #include <errno.h> #include <string.h> int main()
Can someone explain the following two outputs? Code 1: console.log(itemsAry); //loadNextItem(); function loadNextItem(){ var
I have a big csv files with the following format: CSV FILE 1 id,
I have the following javascript code: $.get(categories/json_get_cities/ + stateId, function(result) { //code here },
I have the following code form.label :artists which outputs <label for=artist_artist_name>Artist name</label> How did
The following code compiled with MSVC9.0 runs and outputs Destructor four times, which is

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.