Import and Export in UWP DOCX Editor
18 Aug 20267 minutes to read
The SfRichTextBoxAdv allows you to import and export Word documents (.docx, .doc), rich-text-format documents (.rtf), HTML documents (.htm, .html), and text documents (.txt).
Importing a document
The following sample code demonstrates how to import content from a storage file into SfRichTextBoxAdv.
// Imports the document asynchronously.
async void ImportDocumentAsync()
{
// Initializes the file open picker.
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.FileTypeFilter.Add(".docx");
fileOpenPicker.FileTypeFilter.Add(".doc");
fileOpenPicker.FileTypeFilter.Add(".rtf");
fileOpenPicker.FileTypeFilter.Add(".htm");
fileOpenPicker.FileTypeFilter.Add(".html");
fileOpenPicker.FileTypeFilter.Add(".txt");
// Picks a single storage file using the file open picker.
StorageFile storageFile = await fileOpenPicker.PickSingleFileAsync();
if (storageFile != null)
// Loads the storage file into RichTextBoxAdv asynchronously.
await richTextBoxAdv.LoadAsync(storageFile);
}' Imports the document asynchronously.
Private Async Sub ImportDocumentAsync()
' Initializes the file open picker.
Dim fileOpenPicker As New FileOpenPicker()
fileOpenPicker.FileTypeFilter.Add(".docx")
fileOpenPicker.FileTypeFilter.Add(".doc")
fileOpenPicker.FileTypeFilter.Add(".rtf")
fileOpenPicker.FileTypeFilter.Add(".htm")
fileOpenPicker.FileTypeFilter.Add(".html")
fileOpenPicker.FileTypeFilter.Add(".txt")
' Picks a single storage file using the file open picker.
Dim storageFile As StorageFile = Await fileOpenPicker.PickSingleFileAsync()
If storageFile IsNot Nothing Then
' Loads the storage file into RichTextBoxAdv asynchronously.
Await richTextBoxAdv.LoadAsync(storageFile)
End If
End SubExporting a document
The following code example demonstrates how to export the SfRichTextBoxAdv content as a storage file.
// Exports the document asynchronously.
async void ExportDocumentAsync()
{
// Initializes the file save picker.
FileSavePicker fileSavePicker = new FileSavePicker();
fileSavePicker.FileTypeChoices.Add("Word Document", new List<string>() { ".docx" });
fileSavePicker.FileTypeChoices.Add("Word 97-2003 Document", new List<string>() { ".doc" });
fileSavePicker.FileTypeChoices.Add("Rich Text Format", new List<string>() { ".rtf" });
fileSavePicker.FileTypeChoices.Add("HTML Document", new List<string>() { ".html" });
fileSavePicker.FileTypeChoices.Add("Text Document", new List<string>() { ".txt" });
// Picks the storage file to save.
StorageFile storageFile = await fileSavePicker.PickSaveFileAsync();
if (storageFile != null)
// Saves RichTextBoxAdv content into the storage file asynchronously.
await richTextBoxAdv.SaveAsync(storageFile);
}' Exports the document asynchronously.
Private Async Sub ExportDocumentAsync()
' Initializes the file save picker.
Dim fileSavePicker As New FileSavePicker()
fileSavePicker.FileTypeChoices.Add("Word Document", New List(Of String)() From {".docx"})
fileSavePicker.FileTypeChoices.Add("Word 97-2003 Document", New List(Of String)() From {".doc"})
fileSavePicker.FileTypeChoices.Add("Rich Text Format", New List(Of String)() From {".rtf"})
fileSavePicker.FileTypeChoices.Add("HTML Document", New List(Of String)() From {".html"})
fileSavePicker.FileTypeChoices.Add("Text Document", New List(Of String)() From {".txt"})
' Picks the storage file to save.
Dim storageFile As StorageFile = Await fileSavePicker.PickSaveFileAsync()
If storageFile IsNot Nothing Then
' Saves RichTextBoxAdv content into the storage file asynchronously.
Await richTextBoxAdv.SaveAsync(storageFile)
End If
End SubNOTE
When the
SfRichTextBoxAdvcontrol encounters an unsupported element, it does not render the element. Instead, it continues to the next supported element and renders that.
Examples of unsupported elements are AutoShapes, watermarks, charts, SmartArt, WordArt, equations, document structure tags, styles, wrapping styles, fields other than hyperlinks, absolutely positioned tables, and absolutely positioned images.
Asynchronous loading settings
Show or hide the loading page number
The SfRichTextBoxAdv control shows the current loading page number by default in the bottom-right corner of the control while loading the document asynchronously. You can hide this loading page number by setting the ShowPageNumber property of the LoadAsyncSettings class.
The following code example demonstrates how to hide the loading page number in the SfRichTextBoxAdv control.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv">
<RichTextBoxAdv:SfRichTextBoxAdv.LoadAsyncSettings>
<RichTextBoxAdv:LoadAsyncSettings ShowPageNumber="False" />
</RichTextBoxAdv:SfRichTextBoxAdv.LoadAsyncSettings>
</RichTextBoxAdv:SfRichTextBoxAdv>// Initializes a new instance of SfRichTextBoxAdv.
SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();
// Hides the loading page number.
richTextBoxAdv.LoadAsyncSettings.ShowPageNumber = false;' Initializes a new instance of SfRichTextBoxAdv.
Dim richTextBoxAdv As New SfRichTextBoxAdv()
' Hides the loading page number.
richTextBoxAdv.LoadAsyncSettings.ShowPageNumber = FalseNOTE
This API is supported starting from release version v17.4.0.X.
Events for document load and save notifications
SfRichTextBoxAdv also provides the following events to notify when a document starts and completes loading and saving.
Events table
| Event | Description |
|---|---|
DocumentChanging |
Fires when the document starts loading. |
DocumentChanged |
Fires after the document is successfully loaded. |
DocumentSaving |
Fires when the document starts saving. |
DocumentSaved |
Fires after the document is successfully saved. |
NOTE
These events are supported from Syncfusion UWP RichTextBox v18.2.0.X onwards.