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

Auto-Saving

  • 3 minutes to read

The AutoSave feature supported by office controls helps reduce the risk of data loss by saving an open document automatically at predefined, customizable intervals. This feature is also useful if the Save button is not displayed in the ribbon UI or the ribbon is not used due to the application’s UI constraints.

By default, document AutoSave is off, and you need to use a specific office control level API to enable it.

AutoSave Settings

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

  • The AutoSaveMode property (of the AutoSaveMode type)

    Specifies whether to explicitly enable the auto-saving of documents opened by this particular office control.

    Available values are as follows:

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

        Default - Specifies the default auto-save mode.

  • AutoSaveTimeout property

    Specifies a delay after which the next auto-save operation will be performed.

AutoSave is activated when a document is opened for the first time by an office control whose AutoSaveMode property is set to On. If the same document is opened by several office controls with different AutoSaveMode and AutoSaveTimeout property settings, the document only accepts the On mode for the AutoSave feature, and takes the smallest value for the auto-saving operation timeout. That is, once turned on for an open document, AutoSave cannot be turned off.

Custom Auto-saving - Using the AutoSaving Event

Custom auto-saving invokes a custom save operation on a periodic base similar to the way auto-saving triggers a standard save operation.. See the Standard and Custom Saving topic for details.

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 demonstrates how to assign 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 having 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 server DocumentManager 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