Hello Ramya,
I'm sorry for my late reply. It wasn't possible to send the project as it is a part of a bigger project and the code can't be shared. I figured it out why it was not showing. Because it is loading within a partial view I had to add the following code to the partial view itself
<!-- Syncfusion Essential JS 2 ScriptManager -->
@Html.EJS().ScriptManager()
It is showing but I'm not possible to load a document yet. I added the following line of code in the view, like the example you send me.
@Html.EJS().DocumentEditorContainer("container").ServiceUrl("ap/DocumentEditor/Import").EnableToolbar(true).Render()
at application start we have the following routing in RegisterRoutes
//ASP.NET Web API Route Config
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
And we have a controller
[RoutePrefix("api/documenteditor")]
public class DocumentEditorController : ApiController
{
[HttpPost]
[Route("Import")]
public HttpResponseMessage Import()
{
if (HttpContext.Current.Request.Files.Count == 0)
return null;
HttpPostedFile file = HttpContext.Current.Request.Files[0];
int index = file.FileName.LastIndexOf('.');
string type = index > -1 && index < file.FileName.Length - 1 ?
file.FileName.Substring(index) : ".docx";
Stream stream = file.InputStream;
stream.Position = 0;
EJ2WordDocument document = EJ2WordDocument.Load(stream, GetFormatType(type.ToLower()));
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
return new HttpResponseMessage() { Content = new StringContent(json) };
}
internal static Syncfusion.EJ2.DocumentEditor.FormatType GetFormatType(string format)
{
if (string.IsNullOrEmpty(format))
throw new NotSupportedException("EJ2 DocumentEditor does not support this file format.");
switch (format.ToLower())
{
case ".dotx":
case ".docx":
case ".docm":
case ".dotm":
return Syncfusion.EJ2.DocumentEditor.FormatType.Docx;
case ".dot":
case ".doc":
return Syncfusion.EJ2.DocumentEditor.FormatType.Doc;
case ".rtf":
return Syncfusion.EJ2.DocumentEditor.FormatType.Rtf;
case ".txt":
return Syncfusion.EJ2.DocumentEditor.FormatType.Txt;
case ".xml":
return Syncfusion.EJ2.DocumentEditor.FormatType.WordML;
default:
throw new NotSupportedException("EJ2 DocumentEditor does not support this file format.");
}
}
public string ImportWordDocument(Stream stream)
{
string sfdtText = "";
EJ2WordDocument document = EJ2WordDocument.Load(stream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);
sfdtText = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
return sfdtText;
}