Pursuit Pursuit - 3 months ago 22
Vb.net Question

VB.Net - Write plain text to .txt, keep carriage returns

I have a form where I load .txt files into a RichTextBox. An event triggers:

rtxtSONotes.LoadFile(stTextLink, RichTextBoxStreamType.PlainText)


I want the ability to add to the text and then just replace the old file with the contents of the RichTextBox with a button:

My.Computer.FileSystem.WriteAllText(stTextLink, rtxtSONotes.Text, False)


This actually works great if I stay within the form, it displays exactly how I told it to look in my RichTextBox, meaning all new lines/carriage returns are there. However, if I open the actual .txt file in Notepad then everything is boiled down to one continuous line and is unreadable for most users. I don't want the form to be the only way users can read the file.

Is there a way to preserve carriage returns when writing from a form to a .txt file? I would prefer to keep the files as .txt if possible, rather than something like .rtf.

Answer

maybe something like

System.IO.File.WriteAllLines(stTextLink, rtxtSONotes.Lines)