Skip to main content

WorkbookSaveOptions.DefaultFileName Property

Gets or sets the default file name used for saving a new document.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

public string DefaultFileName { get; set; }

Property Value

Type Description
String

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

Property Paths

You can access this nested property as listed below:

Object Type Path to DefaultFileName
DocumentOptions
.Save .DefaultFileName

Remarks

The DefaultFileName property specifies a file name to be suggested in the Save As dialog invoked for saving a document newly created in the SpreadsheetControl. The WorkbookSaveOptions.DefaultFormat property specifies a format for saving a new document. The file extension for the specified file format is added automatically.

To specify a name that is suggested in the SaveAs file dialog invoked by the SaveDocumentAsCommand command execution, use a Custom SaveAs Command technique illustrated in the following code snippet. The “C:\SavedDocument.xlsx” name is the default file name specified for the Save As dialog.

Example: How to Substitute the Standard Command with Custom Command

using DevExpress.XtraSpreadsheet.Commands;
using DevExpress.XtraSpreadsheet;
using DevExpress.Spreadsheet;
//...

public class CustomSaveDocumentAsCommand : SaveDocumentAsCommand {
    public CustomSaveDocumentAsCommand(ISpreadsheetControl control)
        : base(control) { }

    public override void Execute()
    {
        SaveFileDialog dialog = new SaveFileDialog
        {
            Filter = "Spreadsheet Format Files (*.xlsx)|*.xlsx|All Files (*.*)|*.*",
            FileName = "SavedDocument.xlsx",
            RestoreDirectory = true,
            CheckFileExists = false,
            CheckPathExists = true,
            OverwritePrompt = true,
            DereferenceLinks = true,
            ValidateNames = true,
            AddExtension = false,
            FilterIndex = 1
        };
        dialog.InitialDirectory = "C:\\";
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            ((SpreadsheetControl)this.Control).SaveDocument(dialog.FileName, DocumentFormat.OpenXml);
        }
    }
}
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraSpreadsheet;
using DevExpress.Spreadsheet;
//...

public class CustomService : SpreadsheetCommandFactoryServiceWrapper {
    public CustomService(ISpreadsheetCommandFactoryService service)
        : base(service)
    {
    }
    public SpreadsheetControl Control { get; set; }

    public override SpreadsheetCommand CreateCommand(SpreadsheetCommandId id)
    {
        if (id == SpreadsheetCommandId.FormatClearContents || id == SpreadsheetCommandId.FileSaveAs)
            return new CustomSaveDocumentAsCommand(Control);

        return base.CreateCommand(id);
    }
}
public partial class Form1 : RibbonForm {
    public Form1()
    {
        InitializeComponent();
        SubstituteService();
    }

    private void SubstituteService() {
        ISpreadsheetCommandFactoryService service = (ISpreadsheetCommandFactoryService)spreadsheetControl.GetService(typeof(ISpreadsheetCommandFactoryService));
        CustomService customService = new CustomService(service);
        spreadsheetControl.ReplaceService<ISpreadsheetCommandFactoryService>(customService);
        customService.Control = spreadsheetControl;
    }

}
See Also