File Attachments

17 Feb 20229 minutes to read

The Rich Text Editor allows you to attach a file based on the file upload. You can attach your files using the file upload or drag-and-drop from your local path. When the file upload gets success, the attachment link inserts into the content.

In the below sample, configure the saveUrl and path properties to achieve file attachments.

    1. saveUrl: Provides service URL to save the files.
    2. path: Specifies the location to store the image.

The following sample illustrates how to attach a file in the Rich Text Editor.

        The Rich Text Editor component is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content.
        Users can format their content using standard toolbar commands.
    <p><b> Key features:</b></p>
        <li><p> Provides &lt; IFRAME &gt; and &lt; DIV &gt; modes </p></li>
        <li><p> Capable of handling markdown editing.</p></li>

        <li><p> Contains a modular library to load the necessary functionality on demand.</p></li>

        <li><p> Provides a fully customizable toolbar.</p></li>

        <li><p> Provides HTML view to edit the source directly for developers.</p></li>

        <li><p> Supports third - party library integration.</p></li>

        <li><p> Allows preview of modified content before saving it.</p></li>

        <li><p> Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>

        <li><p> Contains undo / redo manager.</p></li>

        <li><p> Creates bulleted and numbered lists.</p></li>


</div>).InsertImageSettings(obj => obj.SaveUrl("[SERVICE_HOSTED_PATH]/api/uploadbox/Save").Path("../Files/")).Created("created").Render()
@Html.EJS().Uploader("UploadFiles").DropArea(".e-richtexteditor").AsyncSettings(new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = @Url.Content("[SERVICE_HOSTED_PATH]/api/uploadbox/Save")}).Success("onImageUploadSuccess").Render()
    var rteObj;
    var selection = new ej.richtexteditor.NodeSelection();
    var range;
    let saveSelection;
    function created() {
        rteObj = this;
    function onImageUploadSuccess(e) {
        range = selection.getRange(document);
        saveSelection =, document);
        var fileUrl = document.URL + rteObj.insertImageSettings.path +;
         if (rteObj.formatter.getUndoRedoStack().length === 0) {
        rteObj.executeCommand('createLink', { url: fileUrl, text: fileUrl, selection: saveSelection });
public class HomeController : Controller

    public ActionResult Index()
        return View();

To config server-side handler, refer the below code.

int x = 0;
string file;
        public void Save()
                var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadFiles"];
                file = httpPostedFile.FileName;
                if (httpPostedFile != null)
                    var fileSave = System.Web.HttpContext.Current.Server.MapPath("~/Files");
                    if (!Directory.Exists(fileSave))
                    var fileName = Path.GetFileName(httpPostedFile.FileName);
                    var fileSavePath = Path.Combine(fileSave, fileName);
                    while (System.IO.File.Exists(fileSavePath))
                        file = "rte" + x + "-" + fileName;
                        fileSavePath = Path.Combine(fileSave, file);
                    if (!System.IO.File.Exists(fileSavePath))
                        HttpResponse Response = System.Web.HttpContext.Current.Response;
                        Response.Headers.Add("name", file);
                        Response.ContentType = "application/json; charset=utf-8";
                        Response.StatusDescription = "File uploaded succesfully";
                        Response.Headers.Add("url", fileSavePath);
            catch (Exception e)
                HttpResponse Response = System.Web.HttpContext.Current.Response;
                Response.ContentType = "application/json; charset=utf-8";
                Response.StatusCode = 204;
                Response.Status = "204 No Content";
                Response.StatusDescription = e.Message;