aspnet-9859-components-html-editor-concepts-import-and-export.md
ASPxHtmlEditor‘s contents can be imported and exported from/to various document formats. The supported formats include:
Note
DevExpress controls require the DevExpress.RichEdit.v25.2.Export.dll library to export their content to DOCX or RTF format.
You can only implement import operations programmatically. Use an ASPxHtmlEditor.Import method overload for this purpose. This method and its overloads allow you to import editor content from a file or stream, and specify import settings.
The overloaded ASPxHtmlEditor.Import method can include the following import parameters:
filePath
inputStream
format
useInlineStyles
contentFolder
The code below demonstrates how to use the following parameters of the overloaded ASPxHtmlEditor.Import method to import content from a file.
The filePath parameter
The filePath and format parameters
<dx:ASPxButton ID="btnImportFormat" runat="server" onclick="btnImportFormat_Click"
Text="Import by Format" Width="150px">
</dx:ASPxButton>
<dx:ASPxButton ID="btnImportName" runat="server" onclick="btnImportName_Click"
Text="Import by Name" Width="150px">
</dx:ASPxButton>
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server">
</dx:ASPxHtmlEditor>
protected void btnImportFormat_Click(object sender, EventArgs e){
string filePath = @"~/Documents/SampleImportDocument1";
string contentFolder = @"~/Documents/ContentFiles";
//Imports from a DOCX file whose name does not have an extension
ASPxHtmlEditor1.Import(HtmlEditorImportFormat.Docx, filePath, false, contentFolder);
}
protected void btnImportName_Click(object sender, EventArgs e){
string filePath = @"~/Documents/SampleImportDocument2.rtf";
string contentFolder = @"~/Documents/ContentFiles";
//Imports from an RTF file whose name has an extension
ASPxHtmlEditor1.Import(filePath, true, contentFolder);
}
ASPxHtmlEditor allows you to use an export toolbar item that implements export to various document formats. You can also export editor content programmatically on the client and server sides.
ASPxHtmlEditor allows users to export editor content with a drop-down toolbar item (ToolbarExportDropDownButton) that includes all required export functionality. Add this item to the editor’s toolbar and use its ToolbarExportDropDownButton.Items property to access and customize the collection of document formats.
Call an overload of the ASPxHtmlEditor.Export method to save the editor content to a stream or to the response.
The overloaded method can include the following export parameters:
fileName
outputStream
format
saveAsFile
Example
The code below demonstrates how to programmatically export ASPxHtmlEditor content to a file stream or to the response.
<dx:ASPxButton ID="btnExport" runat="server"
Text="Export" Width="150px" onclick="btnExport_Click">
</dx:ASPxButton>
<dx:ASPxButton ID="btnExportToStream" runat="server"
Text="Export to Stream" Width="150px" onclick="btnExportToStream_Click">
</dx:ASPxButton>
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server">
</dx:ASPxHtmlEditor>
protected void btnExportToStream_Click(object sender, EventArgs e){
//Make sure that all required permissions are defined for the folder to which the exported content will be saved.
System.IO.FileStream outputStream = new System.IO.FileStream(MapPath(@"~/Documents/ExportedDocument.rtf"), System.IO.FileMode.Create);
ASPxHtmlEditor1.Export(HtmlEditorExportFormat.Rtf, outputStream);
}
protected void btnExport_Click(object sender, EventArgs e){
ASPxHtmlEditor1.Export(HtmlEditorExportFormat.Pdf, "MyFile");
}
Call the ASPxClientHtmlEditor.ExecuteCommand method with the EXPORT_COMMAND commandName parameter to save the editor content to a file.
The parameter event parameter specifies the file export format. This parameter includes the following values:
The addToUndoHistory event parameter is not in effect for the EXPORT_COMMAND command.
Example
The code below uses the client-side ExecuteCommand method to programmatically export ASPxHtmlEditor content.
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server" ClientInstanceName="htmlEditor">
</dx:ASPxHtmlEditor>
<dx:ASPxButton ID="btnExportToPdf" runat="server" AutoPostBack="False" Text="Export to pdf">
<ClientSideEvents Click="function(s, e) {
htmlEditor.ExecuteCommand(ASPxClientCommandConsts.EXPORT_COMMAND, 'Pdf', false)
}" />
</dx:ASPxButton>
Note
Use the ASPxHtmlEditor.StylesDocument property to specify style settings for an exported document.