Skip to main content

DocumentSaveOptions.DefaultFileName Property

Gets or sets the file name used by default for a new document, when saving or loading a document which has not been previously saved.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.RichEdit.v24.1.Core.dll

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

public string DefaultFileName { get; set; }

Property Value

Type Description
String

A String which represents the default file name (including the path and the file extension).

Property Paths

You can access this nested property as listed below:

Object Type Path to DefaultFileName
RichEditControlOptionsBase
.DocumentSaveOptions .DefaultFileName

Remarks

The DocumentSaveOptions.DefaultFileName property specifies a file name that will be used when saving a newly created document. The DocumentSaveOptions.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 DocumentSaveOptions.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

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.Export;
using DevExpress.XtraRichEdit.Services;

public Form1() {
    InitializeComponent();

    CustomRichEditCommandFactoryService commandFactory = 
        new CustomRichEditCommandFactoryService(richEditControl1, 
            richEditControl1.GetService<IRichEditCommandFactoryService>());
    richEditControl1.ReplaceService<IRichEditCommandFactoryService>(commandFactory);
}
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();
    }
}
See Also