locked
Convert WPF Flowdocument to Plain Text RRS feed

  • Question

  • We have an application in WPF that stores flowdocuments in a SQL DB that users can modify and send to each other within the system.

    My main problem is searching on the flowdocument within the Text column as full text searching matches the flowdocument xaml tags as well. Is there a way to convert a flowdocument to plain text for searching or tell SQL full text searcher how to search flowdocuments?

    Saturday, February 26, 2011 11:32 AM

Answers

  • Hi there,

    My main problem is searching on the flowdocument within the Text column as full text searching matches the flowdocument xaml tags as well. Is there a way to convert a flowdocument to plain text for searching or tell SQL full text searcher how to search flowdocuments?


    not that I know of (which doesn't necessarily mean there is none). Just an idea - what you might be able to do is to store both the formatted and the unformatted text in separate columns of your DB-table (storage is cheap these days). In order to get all the text, you could use something like (untested):

    public static string FlowDocument_GetText(FlowDocument fd)
    {
    	TextRange tr = new TextRange(fd.ContentStart, fd.ContentEnd);
    	return tr.Text;
    }
    


    Cheers,
    Olaf
    http://blogs.intuidev.com
    • Proposed as answer by Yves.Z Tuesday, March 1, 2011 8:23 PM
    • Marked as answer by Yves.Z Monday, March 7, 2011 10:41 AM
    Saturday, February 26, 2011 11:45 AM

All replies

  • Hi there,

    My main problem is searching on the flowdocument within the Text column as full text searching matches the flowdocument xaml tags as well. Is there a way to convert a flowdocument to plain text for searching or tell SQL full text searcher how to search flowdocuments?


    not that I know of (which doesn't necessarily mean there is none). Just an idea - what you might be able to do is to store both the formatted and the unformatted text in separate columns of your DB-table (storage is cheap these days). In order to get all the text, you could use something like (untested):

    public static string FlowDocument_GetText(FlowDocument fd)
    {
    	TextRange tr = new TextRange(fd.ContentStart, fd.ContentEnd);
    	return tr.Text;
    }
    


    Cheers,
    Olaf
    http://blogs.intuidev.com
    • Proposed as answer by Yves.Z Tuesday, March 1, 2011 8:23 PM
    • Marked as answer by Yves.Z Monday, March 7, 2011 10:41 AM
    Saturday, February 26, 2011 11:45 AM
  • Thanks Olaf

    I will give this a try, as long as it returns only the text and no xaml, I am happy to store it as well.

    regards

    Friday, March 4, 2011 6:59 PM
  • Sorry for the late post, the solution above did solve the problem
    Wednesday, March 9, 2011 6:26 PM