Skip to main content
A newer version of this page is available. .

Auto-Saving

  • 3 minutes to read

Office controls include an AutoSave feature that helps reduce the risk of data loss by automatically saving an open document at predefined, customizable intervals. This feature is also useful if the ribbon UI does not display a Save button or the ribbon is not used due to the application’s UI constraints.

The document AutoSave feature is off by default. A specific office control level API is required to enable it.

AutoSave Settings

You can use the following properties to control the AutoSave feature at the office control level.

  • AutoSaveMode property (of the AutoSaveMode type)

    Specifies whether auto-saving is enabled for documents.

    Available values:

    • On - Auto-save mode is explicitly set to “on” for the control.

    • Default - Specifies the default auto-save mode.

  • AutoSaveTimeout property

    Specifies the delay before the next auto-save operation is executed.

If a document is opened by multiple office controls with different AutoSave settings, the AutoSave feature is enabled and the timeout is set to the smallest specified value.

Custom Auto-saving - Using the AutoSaving Event

Custom auto-saving invokes periodic custom save operations in the same way auto-saving triggers a standard save operation. See the following help topic for details: Standard and Custom Saving.

To handle custom save operations triggered by the AutoSave feature, office controls expose the AutoSaving event (DocumentManager.AutoSaving) at the DocumentManager level.

The AutoSaving event uses the same event argument (DocumentSavingEventArgs) as the Saving event of office controls. It is strongly recommended that you declare this event handler as a globally available static method and use it for both events (AutoSaving and Saving).

The following code assigns a handler to the AutoSaving event in the Global.asax file’s Application_Start method.

void Application_Start(object sender, EventArgs e) {
     DevExpress.Web.Office.DocumentManager.AutoSaving += DocumentManager_AutoSaving;
}

static void DocumentManager_AutoSaving(DevExpress.Web.Office.IDocumentInfo documentInfo, DevExpress.Web.Office.DocumentSavingEventArgs e) {
     // Your custom document saving implementation, if required (saving to a database, for instance) 
     // e.Handled = true; 
}

The reason for two similar but separate events is that in contrast to the Saving event, which is declared at the office control level and fired within the ASP.NET page life cycle, the AutoSaving event is declared at the DocumentManager server object level and is fired on the server by a timeout (when there is no access to instances of the ASP.NET page or an office control).

See Also