Programmatically remove parts from an Office file


Kevin Boske has another post on using the System.IO.Packaging assembly to work with the new Office Open XML formats. He shows how you can quickly open the package and navigate the relationships to find a specific part, then remove that part. http://blogs.msdn.com/kevinboske/archive/2006/02/22/537439.aspx


This is great if you want to clean up a file. Let’s say you want to always remove comments from a document before it’s posted on the web. Or maybe you want to remove the VBA from a macro-enabled document before users have access to it. These new open formats give you a lot more control over document entering and leaving your environment.


Kevin also stresses a point I’ve brought up before, and that’s related to part names. It’s important to remember that in Office we rely on the relationships to navigate the packages. We never reference a part directly (always via relationships), and as a result you can’t rely on part names when you are inspecting a file. You need to use the content types part and the relationship files.


-Brian

Comments (4)

  1. Wouter Schut says:

    Wasn’t that always posible by using macro’s? And why doesn’t the example look like normal xml processing?

  2. Please send me email whenever this web site is updated. How can I get the Beta2 version of office 2007?

  3. Dating says:

    Kevin Boske has another post on using the System.IO.Packaging assembly to work with the new Office Open XML formats. He shows how you can quickly open the package and navigate the relationships to find a specific part, then remove that part. http://blogs.msdn.com/kevinboske/archive/2006/02/22/537439.asp

  4. Weddings says:

    Kevin Boske has another post on using the System.IO.Packaging assembly to work with the new Office Open XML formats. He shows how you can quickly open the package and navigate the relationships to find a specific part, then remove that part. http://blogs.msdn.com/kevinboske/archive/2006/02/22/537439.asp