none
Setting ContentType for default entries in Office Open XML package's [Content_Types].xml RRS feed

  • Question

  • I've recently inherited some legacy code, to give you an idea of my familiarity with this subject matter.

    I have a C# application that creates an Excel spreadsheet (.xlsx) by constructing a zip package containing the necessary XML files. The application manually creates the [Content_Types].xml file, and zips the package using Visual J#. I'm trying to get rid of our dependence on Visual J# by using System.IO.Packaging.ZipPackage.

    I can construct the zip package correctly, with all the necessary files. When I add package parts, I set their content type string, which is reflected in [Content_Types].xml. However, [Content_Types].xml is missing a few necessary entries, which Excel interprets as a corrupted file.

    For instance, in a correct content types file, there is a default entry named "rels":

    <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>

    In my zip package, the rels entry has an empty string for the ContentType attribute. Since rels isn't a part in the package, I don't know how to set its ContentType. Is there a way to do this manually?

    Monday, January 7, 2013 4:36 PM

Answers

  • Hi Tom, thanks for the reply.  I took a look at the spec you referenced.  I was able to discover what my problem was.  

    When creating the parts "xl/_rels/workbook.xml.rels" and "xl/worksheets/_rels/datatable.xml.rels" in my ZipPackage, I was leaving their ContentTypes empty.  Setting their content types to "application/vnd.openxmlformats-package.relationships+xml" successfully set the default "rels" part to the correct string.

    Tuesday, January 8, 2013 7:23 PM

All replies

  • Bozalina,

    Thank you for your question.  An engineer from the Protocols Team will contact you soon.


    Bryan S. Burgin Senior Escalation Engineer Microsoft Protocol Open Specifications Team

    Tuesday, January 8, 2013 2:31 AM
    Moderator
  • Hi bozalina,

    In ISO/IEC 29500-2 Annex F, you'll see that the content type listed above in your post is the standard, package-wide type for the relationships part.  Have you tried setting the ContentType to this (i.e. "application/vnd.openxmlformats-package.relationships+xml")?

    Best regards,
    Tom Jebo
    Escalation Engineer
    Microsoft Open Specifications

    Tuesday, January 8, 2013 7:16 AM
    Moderator
  • Hi Tom, thanks for the reply.  I took a look at the spec you referenced.  I was able to discover what my problem was.  

    When creating the parts "xl/_rels/workbook.xml.rels" and "xl/worksheets/_rels/datatable.xml.rels" in my ZipPackage, I was leaving their ContentTypes empty.  Setting their content types to "application/vnd.openxmlformats-package.relationships+xml" successfully set the default "rels" part to the correct string.

    Tuesday, January 8, 2013 7:23 PM
  • Hi Justin,

    Glad to hear you got it working. 

    Tom

    Tuesday, January 8, 2013 11:47 PM
    Moderator