Back to Devexpress

ASPxSpreadsheetBehaviorSettings.SaveAs Property

aspnet-devexpress-dot-web-dot-aspxspreadsheet-dot-aspxspreadsheetbehaviorsettings-d267d989.md

latest4.4 KB
Original Source

ASPxSpreadsheetBehaviorSettings.SaveAs Property

Specifies whether the Save As operation is permitted.

Namespace : DevExpress.Web.ASPxSpreadsheet

Assembly : DevExpress.Web.ASPxSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Web.Office

Declaration

csharp
[DefaultValue(DocumentCapability.Default)]
public DocumentCapability SaveAs { get; set; }
vb
<DefaultValue(DocumentCapability.Default)>
Public Property SaveAs As DocumentCapability

Property Value

TypeDefaultDescription
DocumentCapabilityDefault

The document’s capability to perform an operation. The Default value corresponds to the Enabled value.

|

Available values:

NameDescription
Default

The value is determined by the current setting. The default value is automatically set if it is not explicitly specified.

| | Disabled |

The feature is not allowed and the corresponding commands are shown disabled.

| | Enabled |

The feature is available and the corresponding commands are shown enabled.

| | Hidden |

The feature is not available and the corresponding commands are hidden.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to SaveAs
ASPxSpreadsheetSettings

.Behavior .SaveAs

|

Remarks

The Spreadsheet displays the Save As dialog in the following cases:

  • A user clicks the Save As button.
  • A user clicks the “Save” button, but the document is new and the spreadsheet does not have any information about the path to save this document. The Save As dialog is shown to allow a user to specify the path.

If the SaveAs property is set to Disabled or Hidden, the Save As dialog is blocked and the save operation cannot be performed for a new file. Additionally, the Saving event does not fire because it requires a path to save the document.

In this case, you can use the following workaround: open a new document, save it to the server’s file system, and re-open the document.

csharp
protected void Page_Init(object sender, EventArgs e) {
    ASPxSpreadsheet1.Settings.Behavior.Save = DevExpress.XtraSpreadsheet.DocumentCapability.Enabled;
    ASPxSpreadsheet1.Settings.Behavior.SaveAs = DevExpress.XtraSpreadsheet.DocumentCapability.Hidden;
}
protected void Page_Load(object sender, EventArgs e) {
    if(!Page.IsPostBack) {
        OpenNewDocument();
    }
}

private void OpenNewDocument() {
    var documentName = Guid.NewGuid().ToString();
    var path = Server.MapPath($"{ASPxSpreadsheet1.WorkDirectory}/{documentName}.xlsx");
    ASPxSpreadsheet1.New();
    ASPxSpreadsheet1.SaveCopy(path);
    ASPxSpreadsheet1.Open(path);
}
vb
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
    ASPxSpreadsheet1.Settings.Behavior.Save = DevExpress.XtraSpreadsheet.DocumentCapability.Enabled
    ASPxSpreadsheet1.Settings.Behavior.SaveAs = DevExpress.XtraSpreadsheet.DocumentCapability.Hidden
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Not Page.IsPostBack Then
        OpenNewDocument()
    End If
End Sub

Private Sub OpenNewDocument()
    Dim documentName = Guid.NewGuid().ToString()
    Dim path = Server.MapPath($"{ASPxSpreadsheet1.WorkDirectory}/{documentName}.xlsx")
    ASPxSpreadsheet1.New
    ASPxSpreadsheet1.SaveCopy(path)
    ASPxSpreadsheet1.Open(path)
End Sub

See Also

Save

ASPxSpreadsheetBehaviorSettings Class

ASPxSpreadsheetBehaviorSettings Members

DevExpress.Web.ASPxSpreadsheet Namespace