Saving a RTB in WPF using SaveFileDialog
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Saving a RTB in WPF using SaveFileDialog

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Posts
    7

    Saving a RTB in WPF using SaveFileDialog

    I have a rich text box, and am having difficulty saving my file using the save file dialog (I want to let the user be able to browse to a specific location on their computer.) Could anyone please help me.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,219

    Re: Saving a RTB in WPF using SaveFileDialog

    What exactly are you having trouble with? Can't get the file save dlg to display? Can't write out the data to the file?

  3. #3
    Join Date
    Dec 2009
    Posts
    7

    Re: Saving a RTB in WPF using SaveFileDialog

    Problem Solved now. But I am having one other little issue. When I have a rich text box that is blank, I want a messagbox to display saying that it is not possible to save a blank textbox. I have tried if/else statements but this did not seem to work. Here is the code below.

    private void button4_Click(object sender, RoutedEventArgs e)
    {
    TextRange textRange = new TextRange(richTextBox2.Document.ContentStart, richTextBox2.Document.ContentEnd);
    SaveFileDialog dlg = new SaveFileDialog();
    dlg.Filter = "pdb Files (*pdb) | * pdb";
    if (dlg.ShowDialog() == true)
    {
    using (FileStream fs = new FileStream(dlg.FileName, FileMode.OpenOrCreate))
    {
    textRange.Save(fs, DataFormats.Text);

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,219

    Re: Saving a RTB in WPF using SaveFileDialog

    I would approach that problem differently.

    Instead of being reactive and telling the user that they can't save an empty document after they've tried to save, I would be proactive and only enable the save button if there is something to save.

    To do this, handle the TextChanged event and check the size of the content. If it's zero, then disable the save button; otherwise enable it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center