问题
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:
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);
回答2:
Have you tried:
RichTextBoxStreamType.PlainText
instead of:
PlainText
来源:https://stackoverflow.com/questions/1245758/removing-richtext-formatting-from-richtextbox-in-visual-c-sharp