Click here to Skip to main content
14,392,366 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to write from textboxes in windows form to textfile, I want to use the spilt. I want to be written in the text file like this

Namelabel : NametextBox
passlabel : PasstextBox

how can I do that!

StreamWriter txt = new StreamWriter("D:\\Register.txt")
            
            txt.Write(Namelabel.Text);
            txt.WriteLine(NametextBox.Text);
            txt.Write(passlabel.Text);
            txt.WriteLine(PasstextBox.Text);
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

The problem is that you are not at all writing the colons, or adding a new line to the data when you write it to the file. Try this,

string data = string.Format("{0} : {1}\n{2} : {3}", 
                            Namelabel.Text, 
                            Nametextbox.Text,
                            passlabel.Text, 
                            Passtextbox.Text
               );
txt.Write(data);


What you were missing was that you were simply writing everything without a format being followed. In your template, you are using colons and a new line. In cases where you might want to use a template, I would recommend using a String.Format()[^] method to build the data sample to be saved.
   
Comments
   
5ed.
—SA
Afzaal Ahmad Zeeshan 1-Nov-15 15:34pm
   
Thank you, Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100