Import word document error

Hi,

I am trying to reproduce de sample given in documentation about RTE import word document (https://help.syncfusion.com/js/richtexteditor/importandexport).
When I try to import a word document, I select document as shown in the image "PruebaRTE_View.png" and click ok but nothing happens in the browser. However, in console and in fiddler I could get error messages:  you can see them in images "ErrorConsole.png" and "ErrorFiddler.png"

Here is my code:

MVC CONTROLLER:

public ActionResult PruebaRTE()
        {
            return View();
        }

HTML:

@{
    ViewBag.Title = "PruebaRTE";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>PruebaRTE</h2>
<textarea id="rteSample" rows="10" cols="30" style="width: 740px; height: 440px">
        &lt;p&gt;The Rich Text Editor (RTE) control is an easy to render in
        client side. Customer easy to edit the contents and get the HTML content for
        the displayed content. A rich text editor control provides users with a toolbar
        that helps them to apply rich text formats to the text entered in the text
        area. &lt;/p&gt;
    </textarea>

<script type="text/javascript" class="jsScript">
        $(function () {
            $("#rteSample").ejRTE({
                width:"100%",
minWidth:"150px",
importSettings: {
                     url: "/api/RTE/Import"
                     },
                tools: {
importExport: ["import"]
                }
            });
        });
</script>

API CONTROLLER:

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace Navicare.WebUI.Controllers.Api
{
    public class RTEController : ApiController
    {
        [HttpPost]
        public string Import()
        {
            string HtmlString = string.Empty;
            if (HttpContext.Current.Request.Files.AllKeys.Any())
            {
                string RTEID = HttpContext.Current.Request.QueryString["rteid"];
                var fileName = RTEID + "_importUpload";
                var httpPostedFile = HttpContext.Current.Request.Files[fileName];
                if (httpPostedFile != null)
                {
                    using (var mStream = new MemoryStream())
                    {
                        new WordDocument(httpPostedFile.InputStream).Save(mStream, FormatType.Html);
                        mStream.Position = 0;
                        HtmlString = new StreamReader(mStream).ReadToEnd();
                    };

                    HtmlString = ExtractBodyContent(HtmlString);

                    foreach (var item in DecodeKeys())
                    {
                        HtmlString = HtmlString.Replace(item.Key, item.Value);
                    }
                }
                else HttpContext.Current.Response.Write("Select any file to upload.");

            }
            return HtmlString;
        }

        public IDictionary<string, string> DecodeKeys()
        {
            IDictionary<string, string> KeyValuePair = new Dictionary<string, string>()
            {
               {"\"", "'"},{"\r", " "},{"\n", "<br/> "},{"\r\n", " "},{"( )+", " "},{"&nbsp;", " "},{"&bull;", "*"},{"&lsaquo;", "<"},
               {"&rsaquo;", ">"},{"&trade;", "(tm)"},{"&copy;", "(c)"},{"&reg;", "(r)"}
            };

            return KeyValuePair;
        }

        public string ExtractBodyContent(string html)
        {
            if (html.Contains("<html") && html.Contains("<body"))
            {
                return html.Remove(0, html.IndexOf("<body>") + 6).Replace("</body></html>", "");

            }
            return html;
        }
    }
}


3 Replies

KV Karthikeyan Viswanathan Syncfusion Team August 13, 2018 09:36 AM UTC

Hi Juan,  
    
Based on your share details, we suspect that the issue is raised due to routing URL issue. So, please ensure the importing URL whether it is mentioned properly. Also, we didn’t get your screenshots.   
 
Please find the below code example:   
 
<code>   
$("#rteExport").ejRTE({   
                width:"100%",   
                minWidth: "150px",   
                importSettings: {   
                    url: "/api/Values/Import"   
                },   
                                                exportToWordSettings: {   
                    url: "/api/Values/WordExport", fileName: "WordSample"   
                     },   
                exportToPdfSettings:{   
                    url: "/api/Values/PdfExport", fileName: "PdfSample"   
                     },   
                tools: {   
                    importExport: ["import", "wordExport", "pdfExport"]   
                }   
            });   
</code>   
   
We have prepared a sample based on share code.  Please find the sample link:https://www.syncfusion.com/downloads/support/forum/139202/ze/ImportExportejRTE1595636033    
    
   
Regards,     
Karthikeyan V.  
 



JJ Juan Jose Uribe August 14, 2018 03:12 PM UTC

Yes, you were right, I made a mistake related with routing URL.
Thanks for the sample it helped me to realize my mistake.

Kind regards,

Juan J.


KV Karthikeyan Viswanathan Syncfusion Team August 15, 2018 03:29 AM UTC

Hi Juan, 
 
We are glad to hear that your issue has been resolved.     
 
Regards,  
Karthikeyan V.  


Loader.
Up arrow icon