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

  • Home
  • SEARCH
  • 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 8922943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:58:43+00:00 2026-06-15T06:58:43+00:00

How do I code the whole list into the text file with commas in

  • 0

How do I code the whole list into the text file with commas in between each bit of data? Currently it is creating the file newData, but it is not putting in the variables from the list. Here is what I have so far.

public partial class Form1 : Form {
  List<string> newData = new List<string>();
}

Above is where I create my list. Below is where I am reading it from.

private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
  TextWriter tw = new StreamWriter("NewData.txt");
  tw.WriteLine(newData);
  buttonSave.Enabled = true;
  textBoxLatitude.Enabled = false;
  textBoxLongtitude.Enabled = false;
  textBoxElevation.Enabled = false;
}

And below is where the variables are coming from.

private void buttonSave_Click(object sender, EventArgs e) {
  newData.Add (textBoxLatitude.Text);
  newData.Add (textBoxLongtitude.Text);
  newData.Add (textBoxElevation.Text);
  textBoxLatitude.Text = null;
  textBoxLongtitude.Text = null;
  textBoxElevation.Text = null;
}
  • 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-15T06:58:45+00:00Added an answer on June 15, 2026 at 6:58 am
     private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
    
            TextWriter tw = new StreamWriter("NewData.txt");                       
            tw.WriteLine(String.Join(", ", newData));
    
            // Add appropriate error detection
        }
    

    In response to the discussion in both main answer threads, here is an example from my older code of a more robust way to handle CSV output:

    The above not checked for syntax, but the key concept is String.Join.

     public const string Quote = "\"";
    
     public static void EmitCsvLine(TextWriter report, IList<string> values)
        {
            List<string> csv = new List<string>(values.Count);
    
            for (var z = 0; z < values.Count; z += 1)
            {
                csv.Add(Quote + values[z].Replace(Quote, Quote + Quote) + Quote);
            }
    
            string line = String.Join(",", csv);
    
            report.WriteLine(line);
        }
    

    This could be made slightly more general with an IEnumerable<object> but in the code I took this form, I didn’t have the need to.

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

Sidebar

Related Questions

I am trying to read a large text file (14MB), each line into a
Below is my code and currently it searches the whole webpage. I'm trying to
raw is a data.table and the following code works: raw[,r_responseTime] #Returns the whole column
I have a program reading from a text file (currently 653 lines long) all
I am reading and writting a structure into a text file which is not
I have an XmlReader that is trying to read text into a list of
I am trying to read a file of multiple data types into an ArrayList
I wanted to read certain portions in a text file and add each of
My objective is to read an XML text file and split each word and
I have a text file (myurls.txt) whose contents are a list of URLs as

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.