We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

WordDocument can not be parsed to json

Thread ID:





149794 Dec 9,2019 07:50 PM UTC Dec 11,2019 06:48 AM UTC ASP.NET Core - EJ 2 2
Tags: DocumentEditor
Dagmar Fernandez
Asked On December 9, 2019 07:50 PM UTC

using System;
using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

namespace syncfusion_test.Controllers{
public class ImportController : Controller{

public IActionResult Import(IFormFile file){
Stream stream = new MemoryStream();
int index = file.FileName.LastIndexOf('.');
var type = index > -1 && index < file.FileName.Length - 1 ?
file.FileName.Substring(index) : ".docx";
stream.Position = 0;

WordDocument document = new WordDocument(stream,GetFormatType(type));
var sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(document);
return Ok(sfdt);


static 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 FormatType.Docx;
case ".dot":
case ".doc":
return FormatType.Doc;
case ".rtf":
return FormatType.Rtf;
case ".txt":
return FormatType.Txt;
case ".xml":
return FormatType.WordML;
throw new NotSupportedException("EJ2 DocumentEditor does not support this file format.");

Running this, show this error

Exception has occurred: CLR/Newtonsoft.Json.JsonSerializationException
An exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll but was not handled in user code: 'Error getting value from 'Font' on 'Syncfusion.DocIO.DLS.WCharacterFormat'.' Inner exceptions found, see $exception in variables window for more details. Innermost exception System.NullReferenceException : Object reference not set to an instance of an object.
at Syncfusion.DocIO.DLS.FontSettings.GetFont(String fontName, Single fontSize, FontStyle fontStyle)
at Syncfusion.DocIO.DLS.WCharacterFormat.get_Font()
at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)

What is wrong?.

Suriya Murugan [Syncfusion]
Replied On December 10, 2019 08:32 AM UTC

Thank you for contacting the Syncfusion support. 

## Import word document 
To convert the word document to Json, you have to use the nuget Syncfusion.EJ2.WordEditor.AspNet.Core. 
In provided sample code, you have referred the word document from Syncfusion DocIO. 
Please refer the below sample which contains code for Document importing. 
Please let me know if you have any questions. 


Suriya M. 

Dagmar Fernandez
Replied On December 11, 2019 01:47 AM UTC

Thanks. I was resolved


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon