views:

691

answers:

2

Hi All,

I'm developing an advanced rich text editor in c# but have stumbled upon a problem that I can't seem to grasp.

I have been trying to let users save their documents as Text files (plain text). By using the following:

MyRichTextBox.SaveFile(filepath, PlainText);

But the problem is that when they view that file (which should have been saved as plain text) in Notepad, it shows up with all of the RTF formatting codes whish makes their documents unreadable. Does anybody know of any other way to remove formatting codes from a RichTextBox without having to do too much?

I mean, if there's going to be alot of work involved in finding a workaround to such a simple task, I might as well just create my own RichTextBox control from scratch. Which I'm sure would be very hard to do, but atleast I know that it'll work...

... Sorry for ranting on a little there, hehe...

Thanks All, Jason.

+1  A: 

Have you tried:

RichTextBoxStreamType.PlainText

instead of:

PlainText
dutch
Sorry dutch that's what I did try. I should have made myself more clear. Sorry about that. But yes that's what I have tried. Thank you for your response. The reason I'm on here is because the default/standard way of saving as Text isn't working (RichTextBoxStreamType.PlainText)... I don't know why but it just doesn't save as PlainText... Here's what I have:Myrtb.SaveFile(filepath, RichTextBoxStreamType.PlainText);
baeltazor
+2  A: 

This should do it:

String txt = MyRichTextBox.Text
File.WriteAllText(filepath, txt);

Alternatively, the way to get the RTF is:

String rft = MyRichTextBox.Rtf;
File.WriteAllText(filepath, rtf);
consultutah
Thanks, that was easy. Much appreciated.
baeltazor
Could you mark it as the correct answer? Thank you!
consultutah