Opening document is throws exception - word experienced an error trying to open the file, try these suggestions: check the file permissions for document or drive

Hi Team,
I have a word document which doesn’t have “itemProps.xml” file in “customXml” folder. I have checked this CustomXml by unzipping the docx file.
Do missing itemProps.xml cause issue or we have some workaround on this?

I have attached the template as well below for reference.
TemplateNJ_ReceivedfromSource 1.Docx (16.1 KB)

I have attached the screenshot of error as well.

@dwagh

It sounds like you’re encountering an issue with a Word document that is missing the “itemProps.xml” file in the “customXml” folder. This file is typically used to store custom XML data associated with the document, and its absence can lead to errors when trying to open the file in Word.

Cause: The missing “itemProps.xml” file can result from various factors, including file corruption or improper saving of the document.

Solution: Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Check File Permissions: Ensure that the file permissions for the document and the drive where it is stored allow for reading and writing. Sometimes, restrictive permissions can cause issues when opening files.

  2. Repair the Document: Try using Word’s built-in repair feature. Open Word, go to “File” > “Open,” select the problematic document, and choose “Open and Repair” from the dropdown menu.

  3. Recreate the Custom XML: If you have access to the original data that was supposed to be in the “itemProps.xml,” you could recreate this file and add it back into the “customXml” folder of the document. You can do this by unzipping the .docx file, adding the XML file, and then zipping it back up.

  4. Use Aspose.Words to Load the Document: If you have access to Aspose.Words, you can try loading the document using the library. It may provide more detailed error messages or allow you to manipulate the document programmatically to fix the issue. Here’s a simple code snippet to load a document using Aspose.Words:

    Document doc = new Document("path/to/your/document.docx");
    doc.Save("path/to/save/modified_document.docx");
    
  5. Check for Corruption: If the document is still not opening, it might be corrupted. You can try to recover the content by copying it into a new document.

Next Steps: If these steps do not resolve the issue, please provide more details about the error message or any specific behavior you observe when trying to open the document.

I look forward to your response and am here to help you further!

Hi Team,
This document is stored in one of the source as a byte array and we are fetching documents from source and performing merge operations using aspose linq engine. Complete process is our backend process, so we can’t save and open the document in between to check some permissions or repair the documents.

@dwagh Unfortunately, I cannot reproduce the problem on my side. I can successfully open your document using MS Word on my side. Also, it can be successfully opened by Aspose.Words. The following code does not throw any exceptions:

Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.docx");

Here is the produced output:
out.docx (16.6 KB)

We have some sdt controls in the document and for them we are trying to create the aspose equivalent syntax. First thing is when we are looking for the control metadata we are not able to find.
Below logic we are using to find the control metadata -

/// <summary>
/// Control metadata root element name.
/// </summary>
const string CONTROL_METADATA_KEY = "ApttusMetadata";

public static XNamespace CONTROL_METADATA_SCHEMA = "http://www.apttus.com/schemas";
 
public void UpdateControlMetadata(IDictionary<string, dynamic> controlMetaDictionary)
{
     if (_document == null)
     {
         return;
     }
     var controlXmlParts = _document.Content.CustomXmlParts.Where(c => c.Schemas.Contains(XAuthorConstants.CONTROL_METADATA_SCHEMA.ToString())).ToList();

     for (var i = 0; i < controlXmlParts.Count(); i++)
     {
        _document.Content.CustomXmlParts.RemoveAt(GetCustomPartIndex(_document.Content.CustomXmlParts, controlXmlParts[i]));
     }
 
     // Prepare the new custom xml parts.
     var concurrentDictionary = new ConcurrentDictionary<string, string>();

     Parallel.ForEach(controlMetaDictionary.ToDictionary(x => x.Key, x => (XElement)x.Value), pair =>
     {
         var controlSchemaElement = new XElement("Metadata",
             pair.Value.Elements().Select(x => new XElement(x.Name.LocalName, x.Value)));

         var encodedString = Gzip.Zip(controlSchemaElement.ToSafeString());
         concurrentDictionary.TryAdd(pair.Key, encodedString);
     });
 
     XNamespace ns = XAuthorConstants.CONTROL_METADATA_SCHEMA;
     XName xmlns = "xmlns";

     var xDocument = new XDocument();
     xDocument.Add(new XElement(ns + CONTROL_METADATA_KEY,
                         new XAttribute(xmlns, ns.ToString()),
                         concurrentDictionary.Select
                         (
                             kv => new XElement(ns + "Node",
                                     new XAttribute(ns + "id", kv.Key),
                                     new XAttribute(XNamespace.Xmlns + "p2", ns.ToString()), kv.Value)))
                         );

     // Add the new custom xml parts.
     var customXmlPart = new CustomXmlPart
     {
         Id = IdGenerator.GenerateId(),
         Data = Base64Helper.ToByteArray(Base64Helper.EncodeToBase64(xDocument.ToSafeString()))
     };
     customXmlPart.Schemas.Add(ns.ToString());
     _document.Content.CustomXmlParts.Add(customXmlPart);

     // Reset the dictionary.
     _controlMetaDictionary = controlMetaDictionary.ToDictionary(kv => kv.Key, kv => kv.Value);
}

After this we have created aspose document but we are not able to open that document.
Below I have attached the document for which we are getting the error -
TestCCTemplate15_NJ_Aspose_FromSource.docx (17.5 KB)

@dwagh The document can be opened by the latest 25.8 version of Aspose.Words. After open/save the document with Aspose.Words the document can be successfully opened by MS Word: out.docx (17.5 KB)