RichEditControl.SaveDocument(IWin32Window) Method

Saves a document in its original format to its original location. If original format and location are not specified, invokes the Save As dialog that is shown modally as a child of the specified parent window.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v20.1.dll

Declaration

public virtual bool SaveDocument(
    IWin32Window parent
)
Public Overridable Function SaveDocument(
    parent As IWin32Window
) As Boolean

Parameters

Name Type Description
parent IWin32Window

The IWin32Window that represents the parent window.

Returns

Type Description
Boolean

true if a document has been successfully saved; otherwise, false.

Remarks

Use the SaveDocument method to save changes while editing the document.

The original format is determined by the DocumentSaveOptions.CurrentFormat property. The original location is determined by the DocumentSaveOptions.CurrentFileName property. For the newly created document or a document loaded from a stream, the RichEditControl.SaveDocumentAs method is called.

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.

NOTE

The SaveDocument method call does not automatically change the RichEditControl.Modified property value.

Examples

The following code saves a document to a file. The current RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

static void buttonCustomAction_ItemClick_SaveDocumentMethod(object sender, ItemClickEventArgs e) {
    RichEditControl richEdit = e.Item.Tag as RichEditControl;
    if(MessageBox.Show("Do you want to save this document to the default ('savedResults.docx') location?", 
        "Saving a document", MessageBoxButtons.YesNo) == DialogResult.Yes)

        richEdit.SaveDocument("savedResults.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
    else
        richEdit.SaveDocumentAs();
    System.Windows.Forms.MessageBox.Show("A document was saved sucsessfully");
}
See Also