windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-savedocument-x28-system-dot-windows-dot-forms-dot-iwin32window-x29.md
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.v25.2.dll
NuGet Package : DevExpress.Win.RichEdit
public virtual bool SaveDocument(
IWin32Window parent
)
Public Overridable Function SaveDocument(
parent As IWin32Window
) As Boolean
| Name | Type | Description |
|---|---|---|
| parent | IWin32Window |
The IWin32Window that represents the parent window.
|
| Type | Description |
|---|---|
| Boolean |
true if a document has been successfully saved; otherwise, false.
|
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.
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.Docx);
else
richEdit.SaveDocumentAs();
System.Windows.Forms.MessageBox.Show("A document was saved sucsessfully");
}
Private Shared Sub buttonCustomAction_ItemClick_SaveDocumentMethod(ByVal sender As Object, ByVal e As ItemClickEventArgs)
Dim richEdit As RichEditControl = TryCast(e.Item.Tag, RichEditControl)
If MessageBox.Show("Do you want to save this document to the default ('savedResults.docx') location?",
"Saving a document", MessageBoxButtons.YesNo) = DialogResult.Yes Then
richEdit.SaveDocument("savedResults.docx", DevExpress.XtraRichEdit.DocumentFormat.Docx)
Else
richEdit.SaveDocumentAs()
End If
System.Windows.Forms.MessageBox.Show("A document was saved sucsessfully")
End Sub
See Also