0

I am trying to create a docx file that I can open in open office writer with the following code. The app runs and creates the doc, but when I try to open it I get a "general input/output error" message. If I try to open in word it works fine. Every example I've seen shows to do it this way.

using (var doc = WordprocessingDocument.Create("C:\\tmp\\test123.docx", WordprocessingDocumentType.Document, true))
{
    var mainPart = doc.AddMainDocumentPart();

    mainPart.Document = new Document();
    var docBody = mainPart.Document.AppendChild(new Body());

    for (var i = 0; i <= 7; i++)
        docBody.Append(new Paragraph(new Run(new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sodales orci quis molestie ornare. Nullam id dictum purus."))));

    doc.MainDocumentPart.Document.Save();
    doc.Close();
}

I created a test docx file in ms word and then renamed it and the file created with the code above to zip files. When looking at the contents of the zip file it looks like the code above is not creating a number of files. I don't know if they're needed or not, but wondered if that could be the cause. In the image below, the one on the right is the one that I created in word and it opens fine.

enter image description here

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
geoff swartz
  • 5,437
  • 11
  • 51
  • 75
  • I'm not familiar with Open Office Writer so can only suggest a trouble-shooting step and an observation. 1) Create a basic docx file in OOW then use the Open XML SDK Productivity Tool to compare it to what your code is generating. That will give you an idea of what the application expects. 2) When Word opens an XML document created with "just the basics" (the code shown) it automatically appends the other things required to make a "complete" Word Open XML document. For example, it attaches a complete set of styles, the basic default settings, etc... – Cindy Meister Jul 08 '19 at 10:46
  • ... I can imagine this is the cause of the error: OOW expects at least some of these things to be already present. It would also be interesting to see what's at the next higher hierarchy level in these ZIP packages - are the RELS present in the one on the left? – Cindy Meister Jul 08 '19 at 10:48

0 Answers0