I wanted to know how to send all the entered user information from the textboxes on my form to one text file.

I was thinking I need to say MessageBox.Show("each textbox), but I don't think that is right.

All of this is is login information plus other user data so when it goes in a text file it will be sort of a database.

Please let me know if anyone can help.

Thank you!

Recommended Answers

Get all the textBoxes into an array, and read them (using Text property) into a StringBuilder class. Then write all to a text file:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs) …
Jump to Post

Sure you can do, but you cannot addd comboBox control to TextBox array. But you can add its text additionally, like:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs)
     sb.AppendLine(tb.Text);
//adding text …
Jump to Post

All 7 Replies

Get all the textBoxes into an array, and read them (using Text property) into a StringBuilder class. Then write all to a text file:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs)
     sb.AppendLine(tb.Text);

System.IO.File.WriteAllText(@"C:\myFile.txt", sb.ToString());

Get all the textBoxes into an array, and read them (using Text property) into a StringBuilder class. Then write all to a text file:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs)
     sb.AppendLine(tb.Text);

System.IO.File.WriteAllText(@"C:\myFile.txt", sb.ToString());

Would I be able to add combo box information with this as well or is that something else?

Sure you can do, but you cannot addd comboBox control to TextBox array. But you can add its text additionally, like:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs)
     sb.AppendLine(tb.Text);
//adding text from comboBox too:
sb.AppendLine(comboBox1.SelectedItem.ToString());

System.IO.File.WriteAllText(@"C:\myFile.txt", sb.ToString());

Sure you can do, but you cannot addd comboBox control to TextBox array. But you can add its text additionally, like:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs)
     sb.AppendLine(tb.Text);
//adding text from comboBox too:
sb.AppendLine(comboBox1.SelectedItem.ToString());

System.IO.File.WriteAllText(@"C:\myFile.txt", sb.ToString());

Thank you so much for your help! :)

Anytime mate :)

how to make a read operation with this solution?

@Hatem_1: Please pose your question in a new thread, where you can refer to this one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.