RichTextBox.SaveFile

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Im trying to save a text file using the following code:

RichTextBox t = new RichTextBox();
t.Text = doc.FocusedDocument.Control.Text;
SaveFileDialog saveFile1 = new SaveFileDialog();
saveFile1.FileName = doc.FocusedDocument.Text;
saveFile1.DefaultExt = "*.txt";
saveFile1.Filter = "Text File|*.txt|RTF Files|*.rtf";
if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
saveFile1.FileName.Length > 0)
{
t.SaveFile(saveFile1.FileName, RichTextBoxStreamType.UnicodePlainText);
}

When i try to run the program i get the following error:



An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.



I've checked that the richtextbox contains text and the returned filename is
valid.

Any help would be greatly appreciated.

Thanks

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top