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">
<p>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. </p>
</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", " "},{"( )+", " "},{" ", " "},{"•", "*"},{"‹", "<"},
{"›", ">"},{"™", "(tm)"},{"©", "(c)"},{"®", "(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;
}
}
}