DXRichEditDocumentSaveOptions.DefaultFileName Property
Gets or sets the default file name used when saving or loading a document which has not been previously saved. This is a dependency property.
Namespace: DevExpress.Xpf.RichEdit
Assembly:
DevExpress.Xpf.RichEdit.v24.1.dll
NuGet Package:
DevExpress.Wpf.RichEdit
Declaration
public string DefaultFileName { get; set; }
Public Property DefaultFileName As String
Property Value
Type |
Description |
String |
A String value representing the default file name (including the path and the file extension. )
|
Property Paths
You can access this nested property as listed below:
The DefaultFileName property specifies a file name that will be used when saving a newly created document. The DXRichEditDocumentSaveOptions.DefaultFormat property specifies a format for saving a newly created document. The file extension for the specified file format is added automatically.
If the document has already been saved, the Document.SaveDocument method saves it to the file with the name defined in the DXRichEditDocumentSaveOptions.CurrentFileName property.
To specify a name that is suggested in the SaveAs file dialog invoked via the SaveDocumentAsCommand command, use a Custom SaveAs Command technique illustrated in the following code snippet. The “C:\Temp\SavedDocument.rtf” name is the default file name specified for the Save As dialog.
View Example
public class CustomRichEditCommandFactoryService : IRichEditCommandFactoryService
{
readonly IRichEditCommandFactoryService service;
readonly RichEditControl control;
public CustomRichEditCommandFactoryService(RichEditControl control, IRichEditCommandFactoryService service)
{
DevExpress.Utils.Guard.ArgumentNotNull(control, "control");
DevExpress.Utils.Guard.ArgumentNotNull(service, "service");
this.control = control;
this.service = service;
}
public RichEditCommand CreateCommand(RichEditCommandId id)
{
if (id == RichEditCommandId.FileSaveAs)
return new CustomSaveDocumentAsCommand(control);
return service.CreateCommand(id);
}
}
public class CustomSaveDocumentAsCommand : SaveDocumentAsCommand
{
public CustomSaveDocumentAsCommand(IRichEditControl control)
: base(control) {}
protected override void ExecuteCore()
{
SaveFileDialog dialog = new SaveFileDialog
{
Filter = "Rich Text Format Files (*.rtf)|*.rtf|All Files (*.*)|*.*",
FileName = "SavedDocument.rtf",
RestoreDirectory = true,
CheckFileExists = false,
CheckPathExists = true,
OverwritePrompt = true,
DereferenceLinks = true,
ValidateNames = true,
AddExtension = false,
FilterIndex = 1
};
dialog.InitialDirectory = "C:\\Temp";
if (dialog.ShowDialog() == DialogResult.OK)
{
((RichEditControl)this.Control).SaveDocument(dialog.FileName, DocumentFormat.Rtf);
}
//base.ExecuteCore();
}
}
Public Class CustomRichEditCommandFactoryService
Implements IRichEditCommandFactoryService
Private ReadOnly service As IRichEditCommandFactoryService
Private ReadOnly control As RichEditControl
Public Sub New(ByVal control As RichEditControl, ByVal service As IRichEditCommandFactoryService)
DevExpress.Utils.Guard.ArgumentNotNull(control, "control")
DevExpress.Utils.Guard.ArgumentNotNull(service, "service")
Me.control = control
Me.service = service
End Sub
Public Function CreateCommand(ByVal id As RichEditCommandId) As RichEditCommand Implements IRichEditCommandFactoryService.CreateCommand
If id = RichEditCommandId.FileSaveAs Then
Return New CustomSaveDocumentAsCommand(control)
End If
Return service.CreateCommand(id)
End Function
End Class
Public Class CustomSaveDocumentAsCommand
Inherits SaveDocumentAsCommand
Public Sub New(ByVal control As IRichEditControl)
MyBase.New(control)
End Sub
Protected Overrides Sub ExecuteCore()
Dim dialog As SaveFileDialog = New SaveFileDialog With {.Filter = "Rich Text Format Files (*.rtf)|*.rtf|All Files (*.*)|*.*", .FileName = "SavedDocument.rtf", .RestoreDirectory = True, .CheckFileExists = False, .CheckPathExists = True, .OverwritePrompt = True, .DereferenceLinks = True, .ValidateNames = True, .AddExtension = False, .FilterIndex = 1}
dialog.InitialDirectory = "C:\Temp"
If dialog.ShowDialog() = DialogResult.OK Then
CType(Me.Control, RichEditControl).SaveDocument(dialog.FileName, DocumentFormat.Rtf)
End If
'base.ExecuteCore();
End Sub
End Class
See Also