Saving to multiple text files

how do i append and save multiple text files in vb 2008

Page 1 of 1

2 Replies - 8023 Views - Last Post: 21 January 2008 - 07:59 PM Rate Topic: -----

#1 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

Saving to multiple text files

Post icon  Posted 21 January 2008 - 05:10 PM

Public Class Form1

  

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim Save As New SaveFileDialog()
		Dim myStreamWriter As System.IO.StreamWriter
		myStreamWriter = New System.IO.StreamWriter("C:\Users\Frank\crap.txt")
		myStreamWriter.WriteLine(Text1.Text)
		myStreamWriter.Close()
	


	End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Saving to multiple text files

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Saving to multiple text files

Posted 21 January 2008 - 06:12 PM

Use :code: tags when posting your code. Moved to VB.NET forum.

To set your StreamWriter so that it appends to the file rather than overwriting it, set the second parameter to True. If the file exists then it will append to the end of it, otherwise if the file doesn't exist it will create it.
yStreamWriter = New System.IO.StreamWriter("C:\Users\Frank\crap.txt", True)


To create multiple files, just set the StreamWriter to a new file and write away.

yStreamWriter = New System.IO.StreamWriter("C:\Users\Frank\crap.txt", True)
myStreamWriter.WriteLine(Text1.Text)
yStreamWriter = New System.IO.StreamWriter("C:\Users\Frank\differentfile.txt", True)
myStreamWriter.WriteLine(Text1.Text)

Was This Post Helpful? 0
  • +
  • -

#3 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

Re: Saving to multiple text files

Posted 21 January 2008 - 07:59 PM

:D

Thanks Man

I figured it out except my way was more complicated
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1