writeing and saving to a text document

Shaded

New member
Joined
Feb 7, 2006
Messages
3
Programming Experience
Beginner
Already need help and i am glad i have discovered this site or i would be quite lost so once again here is another probably easy question for you guys but anyways here is what i want to do.

I want to take what is in label1.text and put it in a text doc along with and at the same time label2.text and many more to follow. i want them to be organized on seperate lines so that when i have it read and write stuff from the document. it will take whatever is on line one and put it into label1.text and what ever is one line two to be put into label2.text and so on.

Thank you and i hope someone will have the solution for this.
 
FileStream and StreamWriter.
You will need a Save file dialog on your form for this code. The commented line would immediatly open the textfile with notepad after saving.

VB.NET:
SaveFileDialog1.Filter = "Text Files|*.txt|All Files|*.*"
SaveFileDialog1.FilterIndex = 0
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
     Dim FS As IO.FileStream = SaveFileDialog1.OpenFile
     Dim string1 As String = SaveFileDialog1.FileName
     Dim SW As New IO.StreamWriter(FS)
     SW.Write(Label1.Text & ControlChars.NewLine & Label2.Text)
     SW.Close()
     FS.Close()
     'Shell("notepad.exe " & SaveFileDialog1.FileName, vbNormalFocus)
End If

I'll let you research StreamReader for getting text from a text file into labels.

P.S.
Welcome to the Forum.
 
Back
Top