Hi,
I have a .net core 2.2 WebApp which generates a word document, which is then sent to a clinical system. I used the Open XML SDK tool to provide the code to generate the Word document. This part runs and works fine. The file is generated as a .doc extension:
string fileName = Location + constructedFilename+".doc";
The issue I am facing is, the clinical system (which I don’t control) is rejected the generated word doc. The only message I can retrieve is that the clinical system doesn’t think the document is a valid Word document or it cannot read it.
I have noticed however, if I simply open the generated .doc Word file, Save As another .doc filetype (from the Save As Type dropdown in word), then this file is read by the clinical system.
Another thing I have noticed is regarding the file sizes. The word document generated by Open XML in my webapp is around 20Kb. Once I open that file, and Save As another .doc file (without changing any content) the size of the new file is around 90Kb.
I know this is a bit vague to go on, but any ideas what I should be looking into? I’m a bit stumped.
Thanks
Maybe try saving as .docx? Iirc word can save documents in xml format but as .docx
Have you also tried comparing the 2 files as raw text? There might be some bits you’re missing that word is putting in for you.
Office can be more forgiving when it comes to opening “broken” documents. OpenXML SDK doesn’t tell you which elements are “required”. I don’t know which exact tool you used to generate the file, but pure OpenXML is very obtuse and sometimes missing a small, seemingly unnecessary element or attribute can cause issues.
The OpenXML SDK includes a tool which analyzes OpenXML documents and sometimes tells if some element or attribute is missing. It’s hard to understand though.
As others have suggested you may unpack the two documents, generated and fixed. You can rename the files to .zip and then extract them to get the inner filesystem. You will need to prettify the XML to compare them line-by-line, but the, I don’t know any free XML compare tool, as a simple line-by-line comparison between XML files doesn’t give good information.
C# devs
null reference exceptions