Search code examples
visual-studio-2013c++-clisavefiledialog

c++ Visual Studio Output file error


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?


Solution

  • 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.