0

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!

4
Contributors
7
Replies
16
Views
6 Years
Discussion Span
Last Post by ddanbe
0

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());
0

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?

1

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());
0

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! :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.