Saving from richTextBox to File

G

Guest

Hi, I've got a bunch of text put onto a richTextBox with a StreamWriter.
Every now and then I insert a '\n' character for a new line. It displays
properly in the richTextBox with the \n character moving the text down to the
next line. The problem is that I have it set up so when the user clicks a
button I want to be able to save everything on the richTextBox to a file. It
works properly, but when I view the text file with Notepad, the \n characters
show up as squares instead of moving the text down to the next line. What is
the reason for this and can anyone help?
 
V

Vijaye Raji

Try inserting a '\r' character before the '\n'

'\n' is unix style line ending.

Windows uses CR+LF (Carriage Return + Line Feed). That would be "\r\n"

-vJ
 
G

Guest

Hi guys, thanks for the responses. I've tried both these solutions, but they
don't work. It might be a problem with Notepad or something because if I use
Wordpad to view the output it's formatted correctly. For some reason Notepad
interprets the newline as a character literal. The thing that's got me is
that if I make a call to StreamWriter.NewLine when writing to a file it does
give me a new line rather than the square character. From my understanding
StreamWriter.NewLine simply adds a "\r\n" to the end of what it's writing. So
how come when I add "\r\n" to the end of my strings manually it doesn't work?
What gives? Thanks in advance.

JRB
 
V

Vijaye Raji

If you post a snippet of your code, then, we can try and figure out what's
going on.

-vJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top