收录日期:2020/06/02 03:48:45 时间:2009-08-07 16:31:56 标签:c#,richtextbox,plaintext

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.

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);

Have you tried:

RichTextBoxStreamType.PlainText

instead of:

PlainText