Load docx throw The document appears to be corrupted and cannot be loaded

Env

  • Windows 11
  • Aspose.Words for NET 25.2

Code


void Main()
{
	var doc=new Aspose.Words.Document(@"C:\Users\hello\Desktop\test\test.docx");
}

Test File

test.zip (1.8 MB)

@xxtears

The error message “The document appears to be corrupted and cannot be loaded” typically indicates that the file you are trying to open is not in a valid format or has been damaged. Here are some steps you can take to troubleshoot and potentially resolve this issue:

  1. Check File Integrity: Ensure that the DOCX file is not corrupted. You can try opening it in Microsoft Word or another word processor to see if it opens without issues. If it does not open, the file may indeed be corrupted.

  2. Use LoadOptions: When loading documents, you can specify additional options using the LoadOptions class. This can help in cases where the document has specific requirements or settings. For example, you can set the Microsoft Word version to ensure compatibility:

    LoadOptions loadOptions = new LoadOptions { MswVersion = MsWordVersion.Word2010 };
    var doc = new Aspose.Words.Document(@"C:\Users\hello\Desktop\test\test.docx", loadOptions);
    
  3. Warning Callback: Implement a warning callback to capture any issues that arise during the loading process. This can provide insights into what might be going wrong:

    public class DocumentLoadingWarningCallback : IWarningCallback
    {
        public void Warning(WarningInfo info)
        {
            Console.WriteLine($"WARNING: {info.WarningType}, source: {info.Source}");
            Console.WriteLine($"\tDescription: {info.Description}");
        }
    }
    
    LoadOptions loadOptions = new LoadOptions { WarningCallback = new DocumentLoadingWarningCallback() };
    var doc = new Aspose.Words.Document(@"C:\Users\hello\Desktop\test\test.docx", loadOptions);
    
  4. Check for Encryption: If the document is encrypted, you will need to provide the correct password using the LoadOptions class. If you are unsure whether the document is encrypted, you can use the FileFormatUtil class to check:

    FileFormatInfo info = FileFormatUtil.DetectFileFormat(@"C:\Users\hello\Desktop\test\test.docx");
    if (info.IsEncrypted)
    {
        // Load with password
        var doc = new Aspose.Words.Document(@"C:\Users\hello\Desktop\test\test.docx", new LoadOptions("yourPassword"));
    }
    
  5. Try a Different File: If possible, test with another DOCX file to determine if the issue is specific to the file you are trying to load.

If these steps do not resolve the issue, it may be necessary to investigate the file further or consider reaching out to Aspose support for more detailed assistance.

Sources:
[1]: Document | Aspose.Words for .NET
[2]: Specify Load Options in C#|Aspose.Words for .NET

@xxtears
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27952

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as WORDSNET-27952) have been fixed in this Aspose.Words for .NET 25.4 update also available on NuGet.