none
Getting error: The file contains corrupted data?? openxml packaging wordprocessing document? RRS feed

  • Question

  • hi

    Am trying to open an xml file from a word document and modify parts and save it back as a word doc

    public partial class Form1 : Form { string filepath = ".snip...\\documents\\visual studio 2013\\Projects\\WindowsFormsApplication1\\WindowsFormsApplication1\\xm.xml"; WordprocessingDocument wordprocdocmnt; // = new WordprocessingDocument(); object doc1; public Form1() { InitializeComponent(); try { wordprocdocmnt = WordprocessingDocument.Open(filepath, true); } catch (Exception ex) { MessageBox.Show("error opening document: " + ex.ToString()); } Body body = wordprocdocmnt.MainDocumentPart.Document.Body; }


    the part in the try section fails saying system.io.fileformatexception: file contains corrupted data.  at MS.internal.IO.Zip.ZipIOEndofCentralDirectoryBlock.SeekableLoad(...

    I look this up and find that my xml file is not in the proper format, use the OpenXML SDK 2.5 tool?  no, it says file is corrupted.  this is the xml file from a word doc and i just want to treat various parts of the xml as variables to write my own values.

    so if the sdk 2.5 tool can see the xml then my code probably will too but how to get there from here?? thanks

    Thursday, June 25, 2015 8:04 PM

Answers

  • Hi Bradley,

    >>I look this up and find that my xml file is not in the proper format, use the OpenXML SDK 2.5 tool?  no, it says file is corrupted.  this is the xml file from a word doc and i just want to treat various parts of the xml as variables to write my own values.

    so if the sdk 2.5 tool can see the xml then my code probably will too but how to get there from here??<<

    Based on the error message, the file of document was corrupted. It was expected that we are not able to manipulate it using Open XML SDK.

    The SDK 2.5 tool valid for opening the document may different with the Open SDK. If you want to view the document which corrupted, you can change the document to a zip package.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 26, 2015 10:47 AM
    Moderator

All replies

  • Hi Bradley,

    >>I look this up and find that my xml file is not in the proper format, use the OpenXML SDK 2.5 tool?  no, it says file is corrupted.  this is the xml file from a word doc and i just want to treat various parts of the xml as variables to write my own values.

    so if the sdk 2.5 tool can see the xml then my code probably will too but how to get there from here??<<

    Based on the error message, the file of document was corrupted. It was expected that we are not able to manipulate it using Open XML SDK.

    The SDK 2.5 tool valid for opening the document may different with the Open SDK. If you want to view the document which corrupted, you can change the document to a zip package.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 26, 2015 10:47 AM
    Moderator
  • HI Fei,

    I can now make it work by opening the document, the whole .docx document instead of just the part that has text;  the sdk 2.5 tool opens the docx file and is partly helpful to see the xml tree

    The error was trying to open just part of the document, it was not clear this was the way to use the tool, or the software sdk

    Friday, June 26, 2015 2:40 PM