Your search did not match any results.

Open a File

This demo illustrates how to use the ASP.NET Core Spreadsheet control to open and save files from the server's file system. To enable these operations, set the path to the file system's root folder as the WorkDirectory property's value.

  • To open the document, pass its path as a parameter to the Open method's overload.
  • To save the document in its original format and location, call the Save method without parameters.
@inject IHostingEnvironment env <div class="button-container"> <div id="button-save"></div> </div> <script type="text/javascript"> $("#button-save").dxButton({ icon: "save", type: "normal", text: "Save copy to file", onClick: function (e) { var spreadsheetState = spreadsheet.getSpreadsheetState(); $.ajax({ type: 'POST', url: '@Url.Action("SaveToFile")', data: { spreadsheetState: spreadsheetState } }); } }); </script> @{ var documentPath = System.IO.Path.Combine( env.ContentRootPath, DirectoryManagmentUtils.GetDocumentSampleFolderPath(Context), "EmployeeInformation.xlsx"); } @(Html.DevExpress() .Spreadsheet("spreadsheet") .Height("500px") .Width("100%") .ConfirmOnLosingChanges(confirm => confirm.Enabled(false)) .DocumentRequestHandlerUrl(Url.Action("DxDocumentRequest")) .Open(documentPath) )
using DevExpress.AspNetCore.Spreadsheet; using DevExpress.Spreadsheet; using DevExpress.XtraSpreadsheet.Export; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using System; using System.IO; using System.Linq; using System.Text; namespace AspNetCoreDemos.Spreadsheet { [Route("[action]")] public class DemosController : Controller { public ActionResult FromFile() { return View(); } [HttpPost] public void SaveToFile(SpreadsheetClientState spreadsheetState) { var spreadsheet = SpreadsheetRequestProcessor.GetSpreadsheetFromState(spreadsheetState); spreadsheet.Save(); } } }