Hi Lim,
You can avoid the time delay whenever file upload, you can access the file directly from server side in APP Data folder. Kindly check below code snippet.
Note: Client side you need to pass filename which document you want to open.
Code Snippet:
Client Side:
loadFile(fileName: string) {
var obj = this;
var params = "{fileName: '" + fileName + "'}";
var httpRequest = new XMLHttpRequest();
httpRequest.open('Post', 'http://localhost:62870/api/DocumentEditor/Import?fileName=' + fileName, true);
httpRequest.setRequestHeader("Content-Type", "application/json");
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200 || httpRequest.status === 304) {
//Load Sfdt string in to document editor
obj.container. documentEditor.open(JSON.parse(httpRequest.responseText));
}
else {
// exception
}
}
};
obj.container.documentEditor.documentName = fileName;
httpRequest.send(params);
}
|
Server side:
public string Import (string filename)
{
string path = _hostingEnvironment.ContentRootPath + "\\App_Data\\" + filename + ".docx”.
Stream stream = System.IO.File.OpenRead(path);
stream.Position = 0;
WordDocument document = WordDocument.Load(stream, FormatType.Docx);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
stream.Dispose();
document.Dispose();
return json.
} |
Regarding: If it is a larger file, it will take longer time to load
The DocumentEditor control keeps the entire text contents (text, images, tables, and all other supported elements along with its formatting) of the document and its corresponding information needed for rendering in main memory. In case of opening a Docx file, you may think the file size is small and DocumentEditor utilizes very large memory. Whereas it is a zip archive file with extension “docx”, DocumentEditor control internally decompress it and populate the content in the document object model utilizing remarkable main memory. This is the behaviour of document load in documenteditor.So, DocumentEditor takes some time to load the larger document.
Please let us know if you have any questions.
Regards,
Kurthis Banu A.