Tech Off Thread

9 posts

wpf richtextbox

Back to Forum: Tech Off
  • Metal MilitiA

    is there any way that i can import documents to richtextbox any way is good......

    thanx
    Sevki

  • Cannot​Resolve​Symbol

    Metal MilitiA wrote:
    

    is there any way that i can import documents to richtextbox any way is good......

    thanx
    Sevki



    What kind of documents?  Word documents?  Rich text documents?  HTML documents?  Excel documents?  OpenOffice documents?  Be more specific.

  • Metal MilitiA

    any as in any of those above there is no spesifications any would do..... thanks

  • SEP2007

    I don't know if this is the right answer. But in VB you can do a method called LoadFile(filename), if that is any help.


  • DCMonkey
  • footballism

    public void LoadFile(String path, RichTextBox richTextBox)
    {
        if (!File.Exists(path)) throw new FileNotFoundException("the specified file doesn't exist.");
        String fileExtension = System.IO.Path.GetExtension(path).ToUpper();
        MessageBox.Show(fileExtension.ToString());
        String dataFormat = DataFormats.Text;
        if (fileExtension == "TXT")
        {
            dataFormat = DataFormats.Text;
        }
        else if (fileExtension == "XAML")
        {
            dataFormat = DataFormats.Xaml;
        }
        else if (fileExtension == "RTF")
        {
            dataFormat = DataFormats.Rtf;
        }
        using (FileStream fileStream = File.OpenRead(path))
        {
            TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            if (textRange.CanLoad(dataFormat))
            {
                textRange.Load(fileStream, dataFormat);
            }
        }
    }

    Currently WPF's RichTextBox only supports reading txt, xaml, rtf or xaml package.

    Sheva

  • odujosh

    XHTML and HTML should be added in short order. Add it to your list WPF team.

    Waggles finger.

  • Metal MilitiA

    nks guys you've been great help

  • Shimi Weitzhandler

    odujosh said:

    XHTML and HTML should be added in short order. Add it to your list WPF team.

    Waggles finger.

    I definately agree.

     

    WPF team should add easy-loading support to the following basic docs:

     

    txt

    rtf

    xml ([x]html) etc.

    doc(x)

    pdf (??)

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.