aspnetcore-401876-rich-edit-get-started-web-forms-application.md
This topic describes how to add the client-side RichEdit control to a Web Forms application.
The devexpress-richedit npm package references devextreme-dist as peerDependencies. The peerDependencies packages should be installed manually. This allows developers to control a version of the peerDependencies packages and guarantees that the package is installed once.
Install a RichEdit package with required peerDependencies:
npm init -yYou can find all the libraries in the node_modules folder after the installation is completed.
Create a RichEdit Bundle.
cd node_modules/devexpress-richedit
npm i --save-dev
npm run build-custom
cd ../..
Add scripts into the <head> tag of the Default.aspx page.
<link href="Content/dx.richedit.css" rel="stylesheet" />
<script src="Scripts/dx.richedit.min.js"></script>
Create the Scripts/richedit-creator.js file with the following content.
function createRichEdit(exportUrl, documentAsBase64) {
const options = DevExpress.RichEdit.createOptions();
options.confirmOnLosingChanges.enabled = false;
options.exportUrl = exportUrl;
options.width = '1400px';
options.height = '900px';
var richElement = document.getElementById("rich-container");
const richEdit = DevExpress.RichEdit.create(richElement, options);
if (documentAsBase64)
richEdit.openDocument(documentAsBase64, "DocumentName", DevExpress.RichEdit.DocumentFormat.Rtf);
}
Add scripts into the <head> tag of the Default.aspx page.
<script src="./richedit-creator.js"></script>
How to set RichEdit options | Client-side API code samples
Add a container for RichEdit to the Default.aspx page.
Create a RichEdit Object.
How to set RichEdit options | Client-side API code samples
RichEdit uses post requests to save a document. We recommend that you use the Web API to handle these requests.
Add the following code to the AppStart/RouteConfig.cs file to add a routing for the Web API.
Create the Controllers/RichEditController.cs controller ad populate it with the followig code.
To open a document on RichEdit’s first load, save a document path to a public global variable and pass it to RichEdit’s page.
public string InitialDocument;
...
protected void Page_Load(object sender, EventArgs e)
{
//InitialDocument = Convert.ToBase64String(System.IO.File.ReadAllBytes(
// Server.MapPath($"{documentFolderPath}template.rtf")));
InitialDocument = "e1xydGYxXGRlZmYwe1xmb250dGJse1xmMCBDYWxpYnJpO319e1xjb2xvcnRibCA7XHJlZDB"
+ "cZ3JlZW4wXGJsdWUyNTUgO1xyZWQyNTVcZ3JlZW4yNTVcYmx1ZTI1NSA7fXtcKlxkZWZjaHAgXGZzMjJ9e1xzdHl"
+ "sZXNoZWV0IHtccWxcZnMyMiBOb3JtYWw7fXtcKlxjczFcZnMyMiBEZWZhdWx0IFBhcmFncmFwaCBGb250O317XCp"
+ "cY3MyXGZzMjJcY2YxIEh5cGVybGluazt9e1wqXHRzM1x0c3Jvd2RcZnMyMlxxbFx0c3ZlcnRhbHRcdHNjZWxsY2J"
+ "wYXQyXHRzY2VsbHBjdDBcY2x0eGxydGIgTm9ybWFsIFRhYmxlO319e1wqXGxpc3RvdmVycmlkZXRhYmxlfXtcaW5"
+ "mb31cbm91aWNvbXBhdFxzcGx5dHduaW5lXGh0bWF1dHNwXGV4cHNocnRuXHNwbHRwZ3BhclxkZWZ0YWI3MjBcc2V"
+ "jdGRcbWFyZ2xzeG4xNDQwXG1hcmdyc3huMTQ0MFxtYXJndHN4bjE0NDBcbWFyZ2JzeG4xNDQwXGhlYWRlcnk3MjB"
+ "cZm9vdGVyeTcyMFxwZ3dzeG4xMjI0MFxwZ2hzeG4xNTg0MFxjb2xzMVxjb2xzeDcyMFxwYXJkXHBsYWluXHFse1x"
+ "mczIyXGNmMFxjczEgRG9jdW1lbnQgdGV4dH1cZnMyMlxjZjBccGFyfQ==";
}