I am trying to grab text using
Notice that there are spaces and different height between lines!!!
I work with the text and using
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?????
'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)
There are no ANY spaces between lines and the text has a different format(different height between lines)!!! How to keep the old format?????
6 Answers, 1 is accepted
0
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:
and import:
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
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);
this
.radRichTextBox1.Document =
new
XamlFormatProvider().Import(xaml);
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
0
Anthony
Top achievements
Rank 1
answered on 09 Dec 2010, 11:42 PM
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
0
Palvi
Top achievements
Rank 1
answered on 13 May 2013, 07:30 AM
hi
i am trying to do the same but at the time of import
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
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
0
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
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.
0
Saurabh
Top achievements
Rank 1
answered on 14 Nov 2016, 09:06 AM
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 ?
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 ?
0
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
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.