# Spreadsheet Load an Excel File From Controller

## Environment

<table>
    <tbody>
        <tr>
            <td>Product Version</td>
            <td>2023.3.1010</td>
        </tr>
        <tr>
            <td>Product</td>
            <td>Telerik UI for ASP.NET MVC Spreadsheet</td>
        </tr>
    </tbody>
</table>

## Description

I have a `.xlsx` file on the server and need to load it by default in the Spreadsheet after it initializes.

## Solution

1. Save the file in the **wwwroot/files** directory of the project.

2. Configure the Controller and an Action method that access the file and returns it in JSON format by using the **Telerik.Web.Spreadsheet** dependency.

   ```C# Controller
           using Telerik.Web.Spreadsheet;
           
           public class SpreadsheetController : Controller
           {
               public ActionResult ReadFile()
               {
                   var path = Server.MapPath("~/App_Data/Docs/document.xlsx");
                   var workbook = Telerik.Web.Spreadsheet.Workbook.Load(path);
           
                   //Uses Newtonsoft.Json internally to serialize fields correctly.
                   return Content(workbook.ToJson(), Telerik.Web.Spreadsheet.MimeTypes.JSON);
               }
           }
   ```

3. Set up an Ajax request to the <b>ReadFile</b> Action method and consume the JSON of the response with the use of the [`fromJSON()`](https://docs.telerik.com/kendo-ui/api/ui/spreadsheet/methods/fromjson) method.

   ```JavaScript
       function readFile(){
           $.ajax({
               url: "@Url.Action("ReadFile","Spreadsheet")",
               success: function (e) {
                   var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
                   spreadsheet.fromJSON(e);
               },
               error: function (er) {
                   console.log(er);
               }
           })
       }
   ```

Review the complete implementation and test the behavior at our [Examples repo in GitHub](https://github.com/telerik/ui-for-aspnet-core-examples/blob/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Spreadsheet/Spreadsheet_Load_Xlsx_From_Server.cshtml).

## More ASP.NET MVC Spreadsheet Resources

* [ASP.NET MVC Spreadsheet Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/spreadsheet/overview)

* [ASP.NET MVC Spreadsheet Demos](https://demos.telerik.com/aspnet-mvc/spreadsheet)

* [ASP.NET MVC Spreadsheet Product Page](https://www.telerik.com/aspnet-mvc/spreadsheet)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Spreadsheet for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/spreadsheet)
* [Server-Side API Reference of the Spreadsheet for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/spreadsheet)
* [Understanding Telerik.Web.Spreadsheet and Document Processing Library Spreadsheet Workbook and Worksheets](https://docs.telerik.com/aspnet-core/knowledge-base/spreadsheet-understanding-telerik-web-spreadsheet-and-document-processing-library)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
