adding to a text file  
Author Message
stiflersmom100





PostPosted: Visual Basic Express Edition, adding to a text file Top

I am using streamwriter to write lines of text to a text document as follows:

Using sw As StreamWriter = New StreamWriter("C:\Documents and Settings\User\My Documents\Doc.txt")

My problem is that when I use this, text that was in the document is overwritten. Can I use streamwriter, or something else, to add additional lines of text to an existing document

Thanks



Visual Studio Express Editions8  
 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, adding to a text file Top

absolutely you can use this:

My.Computer.FileSystem.WriteAllText(filename, text, true)

 

or

 

using theFileStream as new FileStream(path, FileMode.Appen, FileAccess.Write)

   using theStreamWriter as new StreamWriter(theFileStream)

      theStreamWriter.WriteLine("boo!")

   end using

end using



 
 
gudel





PostPosted: Visual Basic Express Edition, adding to a text file Top

Just use this one, similar like yours:

Using sw As New IO.StreamWriter("C:\Documents and Settings\User\My Documents\Doc.txt", True)

sw.WriteLine("last line")

End Using


 
 
stiflersmom100





PostPosted: Visual Basic Express Edition, adding to a text file Top

Thanks for the replies.

It works great.