[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect Feature
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
   [Expand]Visual Elements
    Services
    Events
    Commands
    Keyboard Shortcuts
    HTML Tag Support
   [Expand]Examples
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Import and Export

This document describes how to load and save documents in different formats. It consists of the following sections:

Expanded Built-in UI

End users can click the Open button on the File ribbon tab to invoke the Open dialog. Select the file you want to open and click Open.

The Save and Save As buttons on the File ribbon tab allow users to save the changes made to the current document or save it as a new file. Click the Save As button to invoke the Save As dialog used to save a copy as a new file, specify the document's location, name, and format. Refer to the How to: Create the RichEditControl with a Ribbon UI for details on how to provide a ribbon UI for the RichEditControl.

The DocumentSaveOptions.CurrentFileName property returns the current document's file name (including the path and extension).

Tip

You can prohibit end users from creating, loading or saving documents. Set the RichEditBehaviorOptions.CreateNew, RichEditBehaviorOptions.Open, RichEditBehaviorOptions.Save or RichEditBehaviorOptions.SaveAs property to DocumentCapability.Disabled to disable or hide the corresponding commands in the Ribbon UI and pop-up menu.

Expanded Initiate Load and Save Operations in Code

The RichEditControl provides the following methods to load or save the document and specify its options. Refer to the Files examples section for code samples.

Member Description
RichEditControl.LoadDocument Loads a document from a file or stream. The document format can be specified by one of the DocumentFormat enumeration values or detected automatically.
RichEditControl.LoadDocumentTemplate Loads a document template from the specified file or stream so that it cannot be overwritten automatically.
Document.LoadDocument Loads a document from the specified file or stream. Its content can be specified by one of the DocumentFormat enumeration values or is automatically determined based on the file's format.
SubDocument.InsertDocumentContent Inserts content from the selected range into the current document at the specified position.
SubDocument.AppendDocumentContent Appends content from the selected range.
RichEditControl.SaveDocument Saves the control's document to a file or stream and specifies the document's format.
RichEditControl.SaveDocumentAs Invokes the Save As dialog and saves a document.
Document.SaveDocument Saves the document to a file or stream and specifies the document's format.
Note

The SaveDocumentCommand and SaveDocumentAsCommand execution sets the RichEditControl.Modified property to false. The RichEditControl.SaveDocument, RichEditControl.SaveDocumentAs or Document.SaveDocument method call does not automatically change the Modified property value.

Expanded How to: Load and Save a Document

The code sample below loads the document from a file stream when the form is opened and saves the result to the file when the form is closed. Refer to the How to: Load a Document and How to: Save a Document examples for more code samples.

Expanded Basic Format-Specific API

Expanded How to: Handle the BeforeImport Event

Tip

Check the Import and Export examples section for more information on how to accomplish an import- or export-related task.

The code sample below illustrates how to handle RichEditControl.BeforeImport event for different document formats:

Expanded How to: Handle the BeforeExport Event

The code sample below shows how specify export options for different formats in the RichEditControl.BeforeExport event handler.

Expanded Notes on Document Content

  • Control Document Elements

    Use the DocumentCapabilitiesOptions properties to access the DocumentCapabilitiesOptions instance used to control what document elements to import. Specify the options in the RichEditControl.BeforeImport event handler. The restricted elements are lost when the document is saved.

  • HTML Tag Support

    The RichEditControl parses and transforms loaded HTML documents into the internal document model. However, not every HTML tag can be converted into a corresponding document model element. Refer to the HTML Tag Support topic for a list of supported tags.

Expanded See Also

Is this topic helpful?​​​​​​​