We are trying to load the word file, which was not manually created with AltChunks. We are getting an error “The document appears to be corrupted and cannot be loaded”. But when we save the same docx file to disk through microsoft word, the altchunks are applied to OXML and we are able to load the file to Document object. The following are the details:
Code to load the word file:
var document = new Document(filepath);
Full exception stack trace:
Aspose.Words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
---> System.ArgumentException: Cannot insert a node of this type at this location.
at Aspose.Words.CompositeNode.c[T](T d, Node v, Boolean c)
at Aspose.Words.CompositeNode.InsertAfter[T](T newChild, Node refChild)
at Aspose.Words.Node.d[T](T d)
at ZUd.v(StructuredDocumentTag d, Node v)
at ZUd.d()
at aUx.O()
at zUx.wUxiFn()
at wUx.d()
at bU2.t()
at bU2.v()
at fU2.XUfiFd()
at Aspose.Words.Document.v(Stream d, LoadOptions v)
--- End of inner exception stack trace ---
at Aspose.Words.Document.v(Stream d, LoadOptions v)
at Aspose.Words.Document.d(Stream d, LoadOptions v)
at Aspose.Words.Document..ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Words.Document..ctor(Stream stream)
@spglobal
It seems that you are encountering an issue when trying to load a Word document that contains AltChunks, resulting in a “corrupted document” error. This can happen if the document structure is not compliant with the expected format, especially if it was not created or modified using a compatible tool.
Here are a few suggestions to troubleshoot and potentially resolve the issue:
-
Check Document Structure: Ensure that the document adheres to the Open XML standards. Sometimes, documents created by different applications may have structural inconsistencies.
-
Use Microsoft Word to Save: As you mentioned, saving the document through Microsoft Word resolves the issue. This indicates that Word is correcting any structural problems. If possible, always save or export the document using Word before processing it with Aspose.Words.
-
Load Options: When loading documents, consider using specific load options that might help in handling certain document features. For example, you can use LoadOptions
to specify how to handle different aspects of the document.
-
Error Handling: Implement error handling in your code to catch exceptions and log detailed information. This can help you identify the specific part of the document that is causing the issue.
Here is a sample code snippet that demonstrates how to use LoadOptions
when loading a document:
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = LoadFormat.Docx; // Specify the format if known
var document = new Document(filepath, loadOptions);
- Contact Support: If the problem persists, consider reaching out to Aspose support with the problematic document. They may provide insights or fixes specific to your case.
By following these steps, you should be able to diagnose and potentially resolve the loading issue with your Word document containing AltChunks.
If you have any further questions or need additional assistance, feel free to ask!
We can not save the file programmatically, as we could not load the file in first place.
We also tried with LoadOptions, but no luck.
Looks like this not an issue with AltChunks. We create a new file with Altchunk and we are able to load the file with out any issues. Please ignore the above.
@spglobal Could you please attach the problematic input document here for testing? We will check the issue and provide you more information.