javascriptms-officeapps-for-office

Office.context.document.getFileAsync throwing errors


I am getting a very strange issue whereby when I try to extract the word document as a compressed file for processing in my MS Word Task Pane MVC app the third time, it will blow up.

Here is the code:

Office.context.document.getFileAsync(Office.FileType.Compressed, function (result) {
if (result.status == "succeeded") {
    var file = result.value;

    file.getSliceAsync(0, function (resultSlice) {
        //DO SOMETHING
    });
} else {
    //TODO: Service fault handling?
}
});

The error code that comes up is 5001. I am not sure how to fix this.

Please let me know if you have any thoughts on this.

Additional Details:

enter image description here


Solution

  • From MSDN:

    No more than two documents are allowed to be in memory; otherwise the getFileAsync operation will fail. Use the File.closeAsync method to close the file when you are finished working with it.

    Make sure you call File.closeAsync before you read the file again - that could explain the issue you are seeing.

    More at: https://msdn.microsoft.com/en-us/library/office/jj715284.aspx