Integrating into an ASP.NET Core web application enables seamless document editing directly within your web portal. GroupDocs.Editor Cloud SDK for .NET provides a powerful API that lets you load, edit, and save DOCX files on the server. This guide walks you through the required setup, shows step‑by‑step code, and supplies a complete example you can run in minutes. By the end you will be able to add document editing to an ASP.NET Core application with confidence.
Prerequisites and Setup
Before you begin, ensure you have the following:
- .NET 6.0 SDK or later installed
- An IDE such as Visual Studio 2022 or VS Code
- A GroupDocs Cloud account to obtain Client Id and Client Secret
- Access to a Windows, Linux, or macOS development machine
Integrating into an ASP.NET Core web application also requires a reliable network connection to the GroupDocs Cloud endpoints, because all document processing happens remotely. Plan your deployment environment accordingly.
Install the SDK via NuGet:
dotnet add package GroupDocs.editor-Cloud
Download the latest package from the official release page: GroupDocs.Editor Cloud SDK for .NET Download.
Create a configuration object with your credentials (excerpt from the full example):
var configuration = new Configuration
{
ClientId = "client_id",
ClientSecret = "client_secret"
};
With the package installed and credentials ready, you can move on to the implementation. The next sections explain each piece of code in detail, so you understand how the library fits into the overall architecture of an ASP.NET Core web application.
Step-by-Step Guide to Integrating Into an ASP.NET Core Web Application
This section breaks down the process of integrating into an ASP.NET Core web application into discrete, manageable steps. Each step includes a short code fragment taken directly from the reference implementation.
Step 1: Configure API Credentials
First, instantiate the Configuration object with your client details and create the EditorApi client.
var configuration = new Configuration
{
ClientId = "client_id",
ClientSecret = "client_secret"
};
var editorApi = new EditorApi(configuration);
The EditorApi class is documented in the API reference. Initializing the client once per request is sufficient for most scenarios; you can also register it as a singleton in the ASP.NET Core dependency injection container for better performance.
Step 2: Define Load Options
Specify the source file and the desired output location using LoadOptions. This object tells the service which document to open and where to store the rendered HTML.
var loadOptions = new LoadOptions
{
FileInfo = new FileInfo { FilePath = "input.docx" },
RenderOptions = new RenderOptions { OutputPath = "output.html" }
};
LoadOptions, FileInfo, and RenderOptions let you control how the document is rendered for editing. For example, you can set RenderOptions to include images, preserve original styles, or limit the number of pages rendered.
Step 3: Call LoadDocument
Invoke the API to load and convert the document. The call is synchronous in this example, but you can also use the asynchronous version if your controller action is async.
var loadResult = editorApi.LoadDocument(loadOptions);
The LoadDocument method returns a result object containing URLs to the rendered HTML and other metadata. You can store the loadResult for later retrieval or pass the HTML directly to the front‑end.
Step 4: Process Load Result
After loading, you can serve the HTML to the front‑end or store it for later use. This step completes the integrating document editor into ASP.NET Core web app workflow and prepares the document for user interaction.
In a real‑world scenario you would typically return the HTML content from a controller action:
return Content(loadResult.HtmlContent, "text/html");
You may also want to implement caching to avoid re‑loading the same document repeatedly, which can improve response times when integrating into an ASP.NET Core web application at scale.
Integrating Document Editor into ASP.NET Core Web Application - Complete Code Example
The following code demonstrates the entire process from configuration to loading a DOCX file.
var configuration = new Configuration
{
ClientId = "client_id",
ClientSecret = "client_secret"
};
var editorApi = new EditorApi(configuration);
var loadOptions = new LoadOptions
{
FileInfo = new FileInfo { FilePath = "input.docx" },
RenderOptions = new RenderOptions { OutputPath = "output.html" }
};
var loadResult = editorApi.LoadDocument(loadOptions);
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.
Using cURL for ASP.NET Core Document Editing Integration
If you prefer a direct REST approach, the same operation can be performed with cURL commands. This method is useful for quick prototyping or when you need to integrate the editor into a service that is not written in .NET.
1. Authenticate and Get Access Token
curl -X POST "https://api.groupdocs.cloud/v2.0/auth/token" \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
The response contains an access_token used in subsequent calls.
2. Upload the Source File
curl -X POST "https://api.groupdocs.cloud/v2.0/editor/storage/upload?path=/input.docx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "file=@input.docx"
3. Load the Document for Editing
curl -X POST "https://api.groupdocs.cloud/v2.0/editor/load" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"fileInfo": { "filePath": "input.docx" },
"renderOptions": { "outputPath": "output.html" }
}'
4. Download the Rendered HTML
curl -X GET "https://api.groupdocs.cloud/v2.0/editor/storage/download?path=/output.html" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o output.html
These commands illustrate how to add document editing to ASP.NET Core application without writing any C# code, useful for quick testing or integration with other services. For more details, see the official API documentation.
By mastering both the .NET library and the raw REST API, you gain flexibility when integrating into an ASP.NET Core web application, allowing you to choose the approach that best fits your architecture.
