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. https://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
Anonymous
March 12, 2006
Wasn't that always posible by using macro's? And why doesn't the example look like normal xml processing?Anonymous
March 15, 2006
Please send me email whenever this web site is updated. How can I get the Beta2 version of office 2007?Anonymous
May 31, 2008
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.aspAnonymous
June 05, 2008
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