-
Notifications
You must be signed in to change notification settings - Fork 14
1015405: Add "Web Services" Section for Spreadsheet Open/Save in ASP.NET Core & MVC #2412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DinakarManickam4212
wants to merge
11
commits into
development
Choose a base branch
from
EJ2-1015405-dev
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b952d9b
1015405: Add "Web Services" Section for Spreadsheet Open/Save in ASP.…
DinakarSF4212 122d025
Merge branch 'development' into EJ2-1015405-dev
DinakarManickam4212 c2ea9bc
1015405: Resolved CI errors.
DinakarSF4212 54f7450
Merge branch 'EJ2-1015405-dev' of https://github.com/syncfusion-conte…
DinakarSF4212 6c56b1b
1015405: Added changes to the WCF sections and resolved the CI errors.
DinakarSF4212 9247cf8
1015405: Resolved CI errors.
DinakarSF4212 347df8f
Merge branch 'development' into EJ2-1015405-dev
DinakarManickam4212 a019c84
Merge branch 'development' into EJ2-1015405-dev
DinakarManickam4212 7fa08fa
1015405: Review comments addressed.
DinakarSF4212 32840af
1015405: Review comments addressed.
DinakarSF4212 0223a66
Merge branch 'development' into EJ2-1015405-dev
DinakarManickam4212 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...-Processing/Excel/Spreadsheet/React/web-services/webservice-using-aspnetcore.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| --- | ||
| layout: post | ||
| title: Web Services using ASP.NET Core in React Spreadsheet | Syncfusion | ||
| description: Learn here all about web services using ASP.NET Core in React Spreadsheet component of Syncfusion Essential JS 2 and more. | ||
| control: Web Services | ||
| platform: document-processing | ||
| documentation: ug | ||
| --- | ||
|
|
||
| # Connecting Web Services for Spreadsheet Open and Save in ASP.NET Core | ||
|
|
||
| This guide explains how to set up and connect local web services for open and save operations in the Syncfusion Spreadsheet component using ASP.NET Core. | ||
|
|
||
| ## Overview | ||
|
|
||
| By default, the Syncfusion Spreadsheet component uses Syncfusion-hosted endpoints for file operations: | ||
|
|
||
| ```ts | ||
| openUrl: 'https://document.syncfusion.com/web-services/spreadsheet-editor/api/spreadsheet/open', | ||
| saveUrl: 'https://document.syncfusion.com/web-services/spreadsheet-editor/api/spreadsheet/save' | ||
| ``` | ||
|
|
||
| These demo services are intended solely for demonstration purposes and are not recommended for production or development environments. | ||
|
|
||
| ## How-To Guide: Create a Local ASP.NET Core Web API | ||
|
|
||
| ### Create a New ASP.NET Core Web API Project | ||
|
|
||
| Follow the official Microsoft tutorial to create a controller-based Web API project: | ||
|
|
||
| [Tutorial: Create a controller-based web API with ASP.NET Core | Microsoft Learn](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-10.0&source=recommendations&tabs=visual-studio#create-a-web-api-project) | ||
|
|
||
| ### Install Required Dependencies | ||
|
|
||
| For spreadsheet open and save operations, install the following NuGet packages: | ||
|
|
||
| | Platform | Assembly | NuGet Package | | ||
| |---------------|------------------------------------------|---------------| | ||
| | ASP.NET Core | Syncfusion.EJ2.AspNet.Core <br/> Syncfusion.XlsIORenderer.Net.Core | [Syncfusion.EJ2.AspNet.Core](https://www.nuget.org/packages/Syncfusion.EJ2.AspNet.Core) <br/> [Syncfusion.XlsIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIORenderer.Net.Core) | | ||
|
|
||
| For more details, see the [dependencies section on nuget.org](https://www.nuget.org/packages/Syncfusion.EJ2.Spreadsheet.AspNet.Core#dependencies-body-tab). | ||
|
|
||
| ### Add Open and Save Controllers | ||
|
|
||
| Add the following controller actions to enable open and save functionality: | ||
|
|
||
| ```csharp | ||
| // Open action | ||
| [HttpPost] | ||
| [Route("Open")] | ||
| public IActionResult Open([FromForm] IFormCollection openRequest) | ||
| { | ||
| OpenRequest open = new OpenRequest(); | ||
| if (openRequest.Files && openRequest.Files.Count > 0) { | ||
| open.File = openRequest.Files[0]; | ||
| return Content(Workbook.Open(open)); | ||
| } | ||
| return BadRequest("No file uploaded."); | ||
| } | ||
|
|
||
| // Save action | ||
| [HttpPost] | ||
| [Route("Save")] | ||
| public IActionResult Save([FromForm] SaveSettings saveSettings) | ||
| { | ||
| if(saveSettings && saveSettings.JSONData) { | ||
| return Workbook.Save(saveSettings); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Configure File Size Limits | ||
|
|
||
| To support large Excel files, configure file size limits in your server settings. | ||
|
|
||
| **web.config** | ||
| ```xml | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <system.webServer> | ||
| <security> | ||
| <requestFiltering> | ||
| <requestLimits maxAllowedContentLength="2147483647"></requestLimits> | ||
| </requestFiltering> | ||
| </security> | ||
| <directoryBrowse enabled="true" /> | ||
| </system.webServer> | ||
| </configuration> | ||
| ``` | ||
|
|
||
| **Program.cs** | ||
| ```csharp | ||
| builder.Services.Configure<FormOptions>(options => | ||
| { | ||
| options.MultipartBodyLengthLimit = int.MaxValue; | ||
| options.ValueLengthLimit = int.MaxValue; | ||
| }); | ||
|
|
||
| builder.WebHost.ConfigureKestrel(options => | ||
| { | ||
| options.Limits.MaxRequestBodySize = int.MaxValue; | ||
| }); | ||
| ``` | ||
DinakarManickam4212 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### Enable CORS (Cross-Origin Resource Sharing) | ||
|
|
||
| Edit `Program.cs` to allow cross-origin requests: | ||
|
|
||
| ```csharp | ||
| var MyAllowSpecificOrigins = "AllowAllOrigins"; | ||
| builder.Services.AddCors(options => | ||
| { | ||
| options.AddPolicy(MyAllowSpecificOrigins, builder => | ||
| { | ||
| builder.AllowAnyOrigin() | ||
| .AllowAnyMethod() | ||
| .AllowAnyHeader(); | ||
| }); | ||
| }); | ||
|
|
||
| var app = builder.Build(); | ||
| app.UseCors(MyAllowSpecificOrigins); | ||
| ``` | ||
|
|
||
| ### Run the Web API Project | ||
|
|
||
| Build and run your Web API project. For detailed instructions, refer to: | ||
|
|
||
| [Run the ASP.NET Core Web API project](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-10.0&source=recommendations&tabs=visual-studio#run-the-project) | ||
|
|
||
| --- | ||
|
|
||
| ### Configuring the Client-Side URLs | ||
|
|
||
| Once your local service is launched, configure the openUrl and saveUrl properties in client application to use the local endpoints. | ||
|
|
||
| ```js | ||
| <SpreadsheetComponent | ||
| openUrl="https://localhost:5173/api/spreadsheet/open" | ||
| saveUrl="https://localhost:5173/api/spreadsheet/save" | ||
| /> | ||
| ``` | ||
|
|
||
| For more information, refer to the following [blog post](https://www.syncfusion.com/blogs/post/host-spreadsheet-open-and-save-services). | ||
|
|
||
| ## See Also | ||
|
|
||
| * [Docker Image Overview](../server-deployment/spreadsheet-server-docker-image-overview) | ||
| * [Open Excel Files](../open-excel-files) | ||
| * [Save Excel Files](../save-excel-files) | ||
146 changes: 146 additions & 0 deletions
146
...t-Processing/Excel/Spreadsheet/React/web-services/webservice-using-aspnetmvc.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| --- | ||
| layout: post | ||
| title: Web Services using ASP.NET MVC in React Spreadsheet | Syncfusion | ||
| description: Learn here all about web services using ASP.NET MVC in React Spreadsheet component of Syncfusion Essential JS 2 and more. | ||
| control: Web Services | ||
| platform: document-processing | ||
| documentation: ug | ||
| --- | ||
|
|
||
|
|
||
| # Connecting Web Services for Spreadsheet Open and Save in ASP.NET MVC | ||
|
|
||
| This guide explains how to set up and connect local web services for open and save operations in the Syncfusion Spreadsheet component using **ASP.NET MVC**. | ||
|
|
||
| ## Overview | ||
|
|
||
| By default, the Syncfusion Spreadsheet component uses Syncfusion-hosted endpoints for file operations: | ||
|
|
||
| ```ts | ||
| openUrl: 'https://document.syncfusion.com/web-services/spreadsheet-editor/api/spreadsheet/open', | ||
| saveUrl: 'https://document.syncfusion.com/web-services/spreadsheet-editor/api/spreadsheet/save' | ||
| ``` | ||
|
|
||
| These demo services are intended solely for demonstration purposes and are not recommended for production or development environments. | ||
|
|
||
| ## How-To Guide: Create a Local ASP.NET MVC Web Service | ||
|
|
||
| ### Create a New ASP.NET MVC Project | ||
|
|
||
| Follow the official Microsoft tutorial to create an ASP.NET MVC 5 project: | ||
|
|
||
| [Getting Started with ASP.NET MVC 5 | Microsoft Learn](https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started) | ||
|
|
||
| ### Install Required Dependencies | ||
|
|
||
| For spreadsheet open and save operations, install the following NuGet packages: | ||
|
|
||
| | Platform | Assembly | NuGet Package | | ||
| |---------------|------------------------------------------|---------------| | ||
| | ASP.NET MVC5 | Syncfusion.XlsIO.AspNet.Mvc5<br/>Syncfusion.ExcelToPdfConverter.AspNet.Mvc5<br/>Syncfusion.Pdf.AspNet.Mvc5<br/>Syncfusion.ExcelChartToImageConverter.AspNet.Mvc5<br/>Syncfusion.EJ2.MVC5 | [Syncfusion.XlsIO.AspNet.Mvc5](https://www.nuget.org/packages/Syncfusion.XlsIO.AspNet.Mvc5)<br/>[Syncfusion.ExcelToPdfConverter.AspNet.Mvc5](https://www.nuget.org/packages/Syncfusion.ExcelToPdfConverter.AspNet.Mvc5)<br/>[Syncfusion.Pdf.AspNet.Mvc5](https://www.nuget.org/packages/Syncfusion.Pdf.AspNet.Mvc5/)<br/>[Syncfusion.ExcelChartToImageConverter.AspNet.Mvc5](https://www.nuget.org/packages/Syncfusion.ExcelChartToImageConverter.AspNet.Mvc5)<br/>[Syncfusion.EJ2.MVC5](https://www.nuget.org/packages/Syncfusion.EJ2.MVC5) | | ||
|
|
||
| ### Add Open and Save Actions in Controller | ||
|
|
||
| Add the following action methods to your controller (e.g., `SpreadsheetController`) to enable open and save functionality: | ||
|
|
||
| ```csharp | ||
| using System.Web; | ||
| using System.Web.Mvc; | ||
| using Syncfusion.EJ2.Spreadsheet; | ||
|
|
||
| public class SpreadsheetController : Controller | ||
| { | ||
| // Open action | ||
| [HttpPost] | ||
| public ActionResult Open(OpenRequest openRequest) | ||
| { | ||
| if (openRequest != null && openRequest.File != null) | ||
| { | ||
| var result = Workbook.Open(openRequest); | ||
| return Content(result); | ||
| } | ||
| return new HttpStatusCodeResult(400, "No file uploaded."); | ||
| } | ||
|
|
||
| // Save action | ||
| [HttpPost] | ||
| public void Save(SaveSettings saveSettings) | ||
| { | ||
| if(saveSettings && saveSettings.JSONData) { | ||
| Workbook.Save(saveSettings); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Configure File Size Limits | ||
|
|
||
| To support large Excel files, configure file size limits in your server settings. | ||
|
|
||
| **web.config** | ||
| ```xml | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <system.web> | ||
| <httpRuntime maxRequestLength="2097151" executionTimeout="3600" /> | ||
| </system.web> | ||
| <system.webServer> | ||
| <security> | ||
| <requestFiltering> | ||
| <requestLimits maxAllowedContentLength="2147483647"></requestLimits> | ||
| </requestFiltering> | ||
| </security> | ||
| <directoryBrowse enabled="true" /> | ||
| </system.webServer> | ||
| </configuration> | ||
| ``` | ||
|
|
||
| ### Enable CORS (Cross-Origin Resource Sharing) | ||
|
|
||
| Cross-Origin Resource Sharing (CORS) allows your ASP.NET MVC application to accept requests from other domains (such as when your client app and server are running on different ports or hosts). | ||
|
|
||
| **How to Enable CORS in ASP.NET MVC** | ||
|
|
||
| 1. Open `Global.asax.cs` in your project. | ||
| 2. Add the following code to the `Application_BeginRequest` method: | ||
|
|
||
| ```csharp | ||
| protected void Application_BeginRequest() | ||
| { | ||
| // Allow all origins. For production, specify allowed origins instead of '*'. | ||
| HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); | ||
| HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); | ||
| HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept"); | ||
|
|
||
| // Handle preflight requests | ||
| if (HttpContext.Current.Request.HttpMethod == "OPTIONS") | ||
| { | ||
| HttpContext.Current.Response.End(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Run the MVC Project | ||
|
|
||
| After adding the controller codes and above mentioned configurations, build and run the MVC project (F5 or Ctrl+F5 in Visual Studio). | ||
|
|
||
| --- | ||
|
|
||
| ### Configuring the Client-Side URLs | ||
|
|
||
| Once your local service is launched, configure the openUrl and saveUrl properties in client application to use the local endpoints. | ||
|
|
||
| ```js | ||
| <SpreadsheetComponent | ||
| openUrl="https://localhost:44300/Spreadsheet/Open" | ||
| saveUrl="https://localhost:44300/Spreadsheet/Save" | ||
| /> | ||
| ``` | ||
|
|
||
| For more information, refer to the following [blog post](https://www.syncfusion.com/blogs/post/host-spreadsheet-open-and-save-services). | ||
|
|
||
| ## See Also | ||
|
|
||
| * [Docker Image Overview](../server-deployment/spreadsheet-server-docker-image-overview) | ||
| * [Open Excel Files](../open-excel-files) | ||
| * [Save Excel Files](../save-excel-files) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.