Import and Export in WPF RichTextBoxAdv
5 May 20214 minutes to read
This feature lets you use several file formats, namely .doc, .docx, .html, .xaml, and .txt, inside the RichTextBoxAdv control. Using any one format allows the use of the other formats.
HTML Import/Export
The HTML import feature allows the user to import an .html file into the RichTextBoxAdv. It renders the HTML tags like a browser and displays the text in the format of RichTextBoxAdv’s content model. The HTML export feature actually exposes the RichTextBoxAdv’s document as an .html file. The following methods clearly show this use case.
DocumentAdv doucment = HTMLImporting.ConvertToDocumentAdv(stream);
DocumentAdv document = HTMLImporting.ConvertToDocumentAdv(htmlstring);
string html = HTMLExporting.ConvertToHtml(RichTextBox.Document, stream);
Methods
Method | Description | Parameters | Type | Return Type |
---|---|---|---|---|
ConvertToDocumentAdv() | Converts HTML stream into DocumentAdv. | (Stream stream)(string htmlstring) | NA | DocumentAdv |
ConvertToHtml() | Converts the DocumentAdv to an HTML string. | NA | NA | String |
Limitations
The HTML import/export feature has the following limitations:
- Script support has not been provided.
- It does not provide support for tables.
DOC Import/Export and DOCX Import/Export
This feature allows you to open and save the Word DOC and DOCX format (.doc, .docx) documents, and to view, edit, and print the contents by using the RichTextBoxAdv control.
The following assembly references are required to use this feature and its namespace.
WPF 3.5 and 4.0 Framework:
- Assembly: Syncfusion.RichTextDocIOParser.Wpf
- Dependent Assemblies: Syncfusion.Compression.Base, Syncfusion.Core, Syncfusion.DocIO.ClientProfile, Syncfusion.RichTextBoxAdv.Wpf, and Syncfusion.Shared.Wpf
- Namespace: Syncfusion.Windows.Tools.Controls
WPF 4.5 and 4.5.1 Framework:
- Assembly: Syncfusion.RichTextDocIOParser.Wpf
- Dependent Assemblies: Syncfusion.Compression.Base, Syncfusion.Core, Syncfusion.DocIO.Base, Syncfusion.RichTextBoxAdv.Wpf, and Syncfusion.Shared.Wpf
- Namespace: Syncfusion.Windows.Tools.Controls
Silverlight platform:
- Assembly: Syncfusion.RichTextDocIOParser.Silverlight
- Dependent Assemblies: Syncfusion.Compression.Silverlight, Syncfusion.DocIO.Silverlight, Syncfusion.RichTextBoxAdv.Silverlight, and Syncfusion.Shared.Silverlight
- Namespace: Syncfusion.Windows.Tools.Controls
DOC and DOCX Import
You can convert the Word document stream to RichTextBoxAdv document by invoking the ConvertToDocumentAdv method from the extension class DocxImporting.
Method | Return Type | Parameters | Description |
---|---|---|---|
ConvertToDocumentAdv | DocumentAdv | 1. Stream documentStream2. String documentExtension (.doc, .docx) | Converts the Word document stream to DocumentAdv instance. |
//Initializes the new RichTextBoxAdv control.
RichTextBoxAdv richTextBoxAdv = new RichTextBoxAdv();
//Loads the DOC format document in RichTextBoxAdv control from document stream.
richTextBoxAdv.Document = DocxImporting.ConvertToDocumentAdv(documentStream, ".doc");
//Loads the DOCX format document in RichTextBoxAdv control from document stream.
richTextBoxAdv.Document = DocxImporting.ConvertToDocumentAdv(documentStream, ".docx");
'Initializes the new RichTextBoxAdv control.
Dim richTextBoxAdv As New RichTextBoxAdv()
'Loads the DOC format document in RichTextBoxAdv control from document stream.
richTextBoxAdv.Document = DocxImporting.ConvertToDocumentAdv(documentStream, ".doc")
'Loads the DOCX format document in RichTextBoxAdv control from document stream.
richTextBoxAdv.Document = DocxImporting.ConvertToDocumentAdv(documentStream, ".docx")
DOC and DOCX Export
You can convert the RichTextBoxAdv document to Word document stream by invoking the ConvertToDocument method from the extension class DocxExporting.
Method | Return Type | Parameters | Description |
---|---|---|---|
ConvertToDocument | void | 1. DocumentAdv documentadv 2. Stream documentStream 3. String documentExtension (.doc, .docx) | Converts the DocumentAdv instance to Word document stream. |
//Saves the RichTextBoxAdv document to Word DOC format document stream.
DocxExporting.ConvertToDocument(richTextBoxAdv.Document, documentStream, ".doc");
//Saves the RichTextBoxAdv document to Word DOCX format document stream.
DocxExporting.ConvertToDocument(richTextBoxAdv.Document, documentStream, ".docx");
'Saves the RichTextBoxAdv document to Word DOC format document stream.
DocxExporting.ConvertToDocument(richTextBoxAdv.Document, documentStream, ".doc")
'Saves the RichTextBoxAdv document to Word DOCX format document stream.
DocxExporting.ConvertToDocument(richTextBoxAdv.Document, documentStream, ".docx")
Limitations
The .doc import/export and .docx import/export features have the following limitations:
- Hyperlinks do not work for tables of contents.
XAML Import/Export
The XAML import feature allows users to import a .xaml file into the RichTextBoxAdv. It renders the XAML elements as XamlReader and displays the text in the format of RichTextBoxAdv’s content model. The XAML export feature actually exposes the RichTextBoxAdv’s document as a .xaml file. The following methods clearly show this use case.
RichTextBox.Document=XAMLImporting.ConvertToDocumentAdv(xamlStream)
string xaml = XAMLExporting.ConvertToXAML(RichTextBox.Document, xamlstream);
Methods
Method | Description | Parameters | Type | Return Type |
---|---|---|---|---|
ConvertToDocumentAdv() | It converts XAML stream into DocumentAdv. | NA | NA | DocumentAdv |
ConvertToXaml() | It returns the RichText content as XAML. | NA | NA | Void |
Text Import/Export
The text import feature allows the user to import a .txt file into the RichTextBoxAdv. It renders the text in Notepad format and displays the text in the format of RichTextBoxAdv’s content model. The text export feature actually exposes the RichTextBoxAdv’s document as a .txt file. The following methods clearly show this usage.
RichTextBox.Document = TextImporting.ConvertToDocumentAdv(textstream);
string txtstring= TextExporting.ConvertToText(RichTextBox.Document, textStream);
Methods
Method | Description | Parameters | Type | Return Type |
---|---|---|---|---|
ConvertToDocumentAdv() | Converts text stream into DocumentAdv. | NA | NA | DocumentAdv |
ConvertText() | Returns the rich-text content as a text file. | NA | NA | String |