Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,460 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,122 people online right now. Registration is fast and FREE... Join Now!




Saving to multiple text files

 
Reply to this topicStart new topic

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

citricube
21 Jan, 2008 - 04:10 PM
Post #1

New D.I.C Head
*

Joined: 21 Jan, 2008
Posts: 24

CODE
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

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Saving To Multiple Text Files
21 Jan, 2008 - 05:12 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,300



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Use code.gif 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.
CODE

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.

CODE

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)

User is offlineProfile CardPM
+Quote Post

citricube
RE: Saving To Multiple Text Files
21 Jan, 2008 - 06:59 PM
Post #3

New D.I.C Head
*

Joined: 21 Jan, 2008
Posts: 24

biggrin.gif

Thanks Man

I figured it out except my way was more complicated
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 01:54PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month