|
Client-side code:
var documenteditor = containerInstance.documentEditor;
onLoadDefault();
function onLoadDefault() {
var baseUrl = '/api/documenteditor/LoadDefault';
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', baseUrl, true);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200 || httpRequest.status === 304) {
documenteditor.open(httpRequest.responseText);
}
}
};
httpRequest.send();
}
Server-side code:
[AcceptVerbs("Post")]
[HttpPost]
[Route("LoadDefault")]
public string LoadDefault()
{
string path = hostingEnvironment.WebRootPath + "\\DefaultDocument\\Text-Formatting.docx";
//add you file path in above line.
if (!System.IO.File.Exists(path))
return null;
Stream stream = System.IO.File.OpenRead(path);
stream.Position = 0;
WordDocument document = WordDocument.Load(stream, FormatType.Docx);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
stream.Close();
return json;
} |