-1

I'm creating a text editor for one application, using richtextbox to change the text. I have to add a text file with openfiledialog, then save that file to an output file.

I'm using this code to save my file

SaveFileDialog^ saveFile1 = gcnew SaveFileDialog;
if (saveFile1->ShowDialog() == 
    System::Windows::Forms::DialogResult::OK && saveFile1->FileName->Length > 0)
{
  // Save the contents of the RichTextBox1 into the file.
  richTextBox1->SaveFile(saveFile1->FileName);
}

but the following string is added to my output file

{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\lang1036\fs17

I'd like to remove this from my file, does anyone have a solution?

iheb athimni
  • 15
  • 10
  • 3
    You are using a [RichTextBox](https://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox(v=vs.110).aspx), and the output is Rich Text Format (RTF). If you are expecting plain text, perhaps you should be using a plain [TextBox](https://msdn.microsoft.com/en-us/library/system.windows.controls.textbox(v=vs.110).aspx)? – Daniel Waechter Apr 03 '18 at 23:13
  • i m actually using richtextbox to modifie and search in file ,i need to use richtextbox to can do this test and modification , my text is correct in the richtextbox but when i save it he add this RTF format – iheb athimni Apr 04 '18 at 13:11

1 Answers1

0

It looks like the RichTextBox.SaveFile function has a second argument which can be used to specify the format of the file. So instead of calling:

richTextBox1->SaveFile(saveFile1->FileName);

Try calling it like so:

richTextBox1->SaveFile(saveFile1->FileName, RichTextBoxStreamType.PlainText);

And this should save the contents as plain text instead of rich text.

Sean Burton
  • 907
  • 7
  • 15