D
D
dmitry_dev332018-04-07 21:38:29
.NET
dmitry_dev33, 2018-04-07 21:38:29

How to fix incorrect saving of text from RichTextBox to RTF file?

Saving text from the RichTextBox component to an RTF file does not work correctly. What is interesting: when stepping through the code, saving is performed, but during a normal launch it is not (the file is empty). What could be the problem?

if (richTextBoxWrite.Text != null)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                // sfd.Filter = "RTF files|*.rtf";
                sfd.Filter = "txt files (*.rtf) | *.rtf | All files(*.*) | *.*";
                if ((sfd.ShowDialog() == DialogResult.OK) && (sfd.FileName.Length > 0))
                {
                    string filename = sfd.FileName;
                    richTextBoxWrite.SaveFile(filename, RichTextBoxStreamType.RichText);
                }
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Codebaker, 2018-04-24
@Codebaker

Try replacing the first condition with:

if (!string.IsNullOrWhiteSpace(richTextBoxWrite.Text)) {
                ....
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question