Problem with using Telerik.Windows.Documents.FormatProviders.Txt.TxtFormatProvider()

7 posts, 0 answers
  1. Anthony
    Anthony avatar
    33 posts
    Member since:
    Nov 2010

    Posted 02 Dec 2010 Link to this post

    I am trying to grab text using 

    'get text from RadRichTextBox
    Dim oExporter As Telerik.Windows.Documents.FormatProviders.ITextBasedDocumentFormatProvider = New Telerik.Windows.Documents.FormatProviders.Txt.TxtFormatProvider()
    Dim sText As String = oExporter.Export(RadRichTextBox.Document)

    the text :

    Test Text 2 Document 

    Merging Just a client

    Given Name:  «cGiven»
    surname:       «cSurname»

    title: «cTitle»
    the text :

    Test Text 2 Document 

    Merging Just a client

    Given Name:  «cGiven»
    surname:       «cSurname»

    title: «cTitle»
    the text :
    the text :
     
    Test Text 2 Document
     
    Merging Just a client
     
    Given Name:  «cGiven»
    surname:       «cSurname»
     
    title:  «cTitle»
    Notice that there are spaces and different height between lines!!!
    I work with the text and using 

    Notice that there are spaces and different height between lines!!!
    I work with the text and using
    RadRichTextBox.Document = oExporter.Import(sText)
    I return it back into the control.... BUT
    There are no ANY spaces between lines and the text has a different format(different height between lines)!!! How to keep the old format?????




  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 06 Dec 2010 Link to this post

    Hello Anthony,
    TxtFormatProvider exports document's content to plain text, thus all the formatting is lost. If you want to preserve it, your best option is to use XamlFormatProvider, located in Telerik.Windows.Documents.FormatProviders.Xaml.dll assembly:
    string xaml = new XamlFormatProvider().Export(this.radRichTextBox.Document);
    and import:
    this.radRichTextBox1.Document = new XamlFormatProvider().Import(xaml);
    where xaml could be string, byte array or stream.
    You can check the Import/Export help article for more information.

    Greetings,
    Boby
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Anthony
    Anthony avatar
    33 posts
    Member since:
    Nov 2010

    Posted 09 Dec 2010 Link to this post

    Thank you for a reply... Really it was my mistake..I really forgot about text formatting for pure txt((( again thank you for the response... it works properly
  5. Palvi
    Palvi avatar
    1 posts
    Member since:
    May 2013

    Posted 13 May 2013 Link to this post

    hi 
    i am trying to do the same but at the time of import
    this.radRichTextBox1.Document = new XamlFormatProvider().Import(xaml);
     i am getting the exception like:

    {System.NullReferenceException: Object reference not set to an instance of an object." & vbCrLf & "  
     at CAN.General.Utilities.GeneralNotes.ViewModel.AddNoteViewVM.RetrieveCompleteNoteInfoHandler
     (CompleteNoteInfoForSalesTaskBE resultNoteDetail)}

    Please help me in this 
    Thanks in advance
  6. Petya
    Admin
    Petya avatar
    975 posts

    Posted 13 May 2013 Link to this post

    Hi Palvi,

    I saw you started a support ticket on the same topic. As it is hard for us to pinpoint the problem, I suggest we continue our communication in the ticket where you can attach files for our reference.

    Regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Saurabh
    Saurabh avatar
    1 posts
    Member since:
    Nov 2016

    Posted 14 Nov Link to this post

    We are using RadRichTextBox to enter the Text and below code to get Xaml string.

    XamlFormatProvider provider = new XamlFormatProvider();
    string xamlStr = provider.Export(document);

    If we enter the text starting with curly braces ('{') in RadRichTextBox then it is returning an extra curly braces('{}') along with the entered text ('{') in provider.Export(document).
    Example :
     Enterted Text :- {ASD}
     Returned Text :- {}{ASD}

    Returned Xmal string :-

    <t:RadDocument xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:t=\"clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents\" xmlns:s=\"clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents\" xmlns:r=\"clr-namespace:Telerik.Windows.Documents.Model.Revisions;assembly=Telerik.Windows.Documents\" xmlns:n=\"clr-namespace:Telerik.Windows.Documents.Model.Notes;assembly=Telerik.Windows.Documents\" xmlns:th=\"clr-namespace:Telerik.Windows.Documents.Model.Themes;assembly=Telerik.Windows.Documents\" version=\"1.2\" LayoutMode=\"Flow\" LineSpacing=\"1.15\" LineSpacingType=\"Auto\" ParagraphDefaultSpacingAfter=\"12\" ParagraphDefaultSpacingBefore=\"0\" SelectedBibliographicStyleName=\"\\APA.XSL\" StyleName=\"defaultDocumentStyle\">\r\n  <t:RadDocument.Captions>\r\n    <t:CaptionDefinition IsDefault=\"True\" IsLinkedToHeading=\"False\" Label=\"Figure\" LinkedHeadingLevel=\"0\" NumberingFormat=\"Arabic\" SeparatorType=\"Hyphen\" />\r\n    <
    t:CaptionDefinition IsDefault=\"True\" IsLinkedToHeading=\"False\" Label=\"Table\" LinkedHeadingLevel=\"0\" NumberingFormat=\"Arabic\" SeparatorType=\"Hyphen\" />\r\n  </t:RadDocument.Captions>\r\n  <t:RadDocument.ProtectionSettings>\r\n    <t:DocumentProtectionSettings EnableDocumentProtection=\"False\" Enforce=\"False\" HashingAlgorithm=\"None\" HashingSpinCount=\"0\" ProtectionMode=\"ReadOnly\" />\r\n  </t:RadDocument.ProtectionSettings>\r\n  <t:RadDocument.Styles>\r\n    <s:StyleDefinition DisplayName=\"Document Default Style\" IsCustom=\"False\" IsDefault=\"False\" IsPrimary=\"True\" Name=\"defaultDocumentStyle\" Type=\"Default\">\r\n      <s:StyleDefinition.ParagraphStyle>\r\n        <s:ParagraphProperties LineSpacing=\"1.15\" SpacingAfter=\"12\" />\r\n      </s:StyleDefinition.ParagraphStyle>\r\n      <s:StyleDefinition.SpanStyle>\r\n        <s:SpanProperties FontFamily=\"Portable User Interface\" FontSize=\"11\" FontStyle=\"Normal\" FontWeight=\"Normal\" />\r\n      </s:StyleDefinition.SpanStyle>\r\n  
      </s:StyleDefinition>\r\n    <s:StyleDefinition DisplayName=\"Normal\" IsCustom=\"False\" IsDefault=\"True\" IsPrimary=\"True\" Name=\"Normal\" Type=\"Paragraph\" />\r\n    <s:StyleDefinition DisplayName=\"TableNormal\" IsCustom=\"False\" IsDefault=\"True\" IsPrimary=\"True\" Name=\"TableNormal\" Type=\"Table\">\r\n      <s:StyleDefinition.TableStyle>\r\n        <s:TableProperties CellPadding=\"5,0,5,0\">\r\n          <s:TableProperties.TableLook>\r\n            <t:TableLook />\r\n          </s:TableProperties.TableLook>\r\n        </s:TableProperties>\r\n      </s:StyleDefinition.TableStyle>\r\n    </s:StyleDefinition>\r\n  </t:RadDocument.Styles>\r\n  <t:Section>\r\n    <t:Paragraph>\r\n      <t:Span Text=\"{}{ASD}\" />\r\n    </t:Paragraph>\r\n  </t:Section>\r\n</t:RadDocument>


    Can anyone explain why and how it is occurring ? Is there any solution to remove extra curly braces ?
  8. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 16 Nov Link to this post

    Hi Saurabh,

    The value you are getting is as a result of the escaping of the attribute's value and is expected. Due to the specifics of the XAML language, strings starting with a curly bracket are always escaped. Otherwise, they are treated as the start of a markup extension and the XamlReader, which is internally used by the format provider, will throw an exception.

    With that said, I am afraid that there is not much you can do to avoid adding the additional curly brackets. 

    Regards,
    Tanya
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
DevCraft banner