Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[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]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
    Overview
   [Expand]Getting Started
   [Expand]Fundamentals
   [Expand]Concepts
   [Expand]Visual Elements
   [Collapse]Examples
    [Collapse]Files
      How to: Create a New Document with the RichEdit Control
      How to: Load a Document into the RichEdit Control
      How to: Save a Document in the RichEdit Control
    [Expand]Text
    [Expand]Formatting
    [Expand]Styles
    [Expand]Lists
    [Expand]Pictures
    [Expand]Text Boxes
    [Expand]Tables
    [Expand]Layout
    [Expand]Automation
    [Expand]Search and Replace
    [Expand]Mail Merge
    [Expand]Spell Check
    [Expand]Export-Import
    [Expand]Printing
    [Expand]Protection
    [Expand]User Interface Customization
    [Expand]Miscellaneous
    [Expand]Commands
   [Expand]Member Tables
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Save a Document in the RichEdit Control

Expanded Common Technique

To save a document in the RichEditControl use the Document.SaveDocument method. The RichEditControlOptionsBase.DocumentSaveOptions property provides access to information about the current and default file names and formats.

Call the RichEditControl.SaveDocumentAs method to invoke a Save As... dialog.

Note

Consider the situation when a document is being saved to a locked or read-only file. To prevent application failure, subscribe to the RichEditControl.UnhandledException event and set the RichEditUnhandledExceptionEventArgs.Handled property to true.

The RichEditControl.BeforeExport event is raised before you save a document. You can handle this event to check how the exporter formats a document. For example, the following code snippet determines whether or not a document contains complex formatting elements (inline pictures). If they are found, the user is prompted to save the metafile representation along with the original picture (by enabling the RtfDocumentExporterCompatibilityOptions.DuplicateObjectAsMetafile property). This technique increases the file size, but makes it possible to open this file with third-party editors which don't support native picture format.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E1401.

Expanded Custom SaveAs Command

You can implement a custom command to adjust the SaveAs dialog settings or accomplish specific tasks.

Note

Commands executed via the Bar (Ribbon) user interface can throw unhandled exceptions if a problem occurs. Consider the situation when a document is being saved to a locked or read-only file. To prevent application failure, subscribe to the RichEditControl.UnhandledException event and set the RichEditUnhandledExceptionEventArgs.Handled property to true.

A custom command inherits from the SaveDocumentAsCommand class and overrides the protected ExecuteCore method. To substitute default command with a custom command, create a new command factory - the class that implements the IRichEditCommandFactoryService interface and intercepts a call that creates a SaveDocumentAsCommand command. Register the new command factory via the IRichEditDocumentServer.ReplaceService<T> method and the RichEditControl will execute a custom command whenever you press F12 or click the Save As... button.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E1401.

Expanded Save in Format with External Content

When saving a document in a format that defines an external content included via links (HTML format), specify a base URI to store these objects (images and style sheets). This involves RichEditControl.BeforeExport event handling and custom IUriProvider interface implementation.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E1604.

Expanded See Also

How would you rate this topic?​​​​​​​