June 2008 - Posts

PowerTools for Open XML

One of the namespaces introduced in the .NET Framework 3.0 is System.IO.Packaging (in the WindowsBase assembly), which provides classes that support storage of multiple data objects in a single container, like a ZIP file. These data objects can be referenced in a hierarchical format, similar to the file system. This functionality can be used to open, read and manipulating the files based on the Open XML standard since the Open XML file format follows the same principle. A while back, I wrote a piece of code for a customer to use the classes in this namespace for setting the values for custom properties in Word 2007 documents and Excel 2007 spreadsheets. This wasn't hard but I had to use XPath queries and use the appropriate XML namespaces in order to find the elements I was trying to update.

We then had an initiative to create an SDK that provides strongly-typed part classes for use with the documents based on Open XML. This SDK was available in CTP mode until earlier this week when its first version was released. You can now download the Open XML Format SDK from the Download Center. This SDK relies on the functionality provided by the System.IO.Packaging namespace so it requires .NET Framework 3.0.

The Open XML Format SDK makes the life so much easier for the developers, but wait... we are not finished yet. Right after the release of the Open XML Format SDK, another open source project called "PowerTools for Open XML" was announced, which provides more than 30 PowerShell cmdlets to manipulate the Open XML files. So for example, there are cmdlets for manipulating the watermark, header and footer, style, etc. This means you can read and edit Open XML files on the server-side without using the Office object model and without a need for an Office 2007 license on the server machine. Here is a great screencast that includes some nice demos that show how you can use the PowerTools to go through a list of Word documents, add a watermark to all of them and make sure they all use the same text style. There is also another demo that performs a mail merge using a simple PowerShell script.


Video: PowerTools for Open XML Introduction

I remember that a few years back, I was working on a project where the customer decided to spend a considerable amount of cash on a document generation and rendering solution and the development team had to write a lot of code to populate the templates provided by the third-party solution. The integration and testing experience was quite painful too. It is great to see how the publication of Open XML as a standard and the development of great tools by Microsoft and the open source community has simplified the document generation process and I can clearly see how this will result in reduction of licensing and development costs.

Where is the Configuration Management Application Block?

This is not a new topic but since this question has been asked a few times recently, here is a quick revisit:

Most of the .NET applications use configuration management and that's why the basic support for configuration management has been included in the .NET Framework from the early versions. The configuration management functionality is provided by the classes in the System.Configuration namespace in the System assembly. But the requirements for configuration management usually go beyond the basic functionality provided by these components so one had to write lots of code to meet the application requirements using the out-of-the-box functionality. This is why the patterns and practices team developed the Configuration Management Application Block.

This application block proved to be a very popular one so the .NET Framework team decided to build this functionality into the framework, beginning with the .NET Framework 2.0. As a result, the Configuration Management Application Block was removed from the Enterprise Library 2.0 and some of the helper classes and design-time components were moved to the Enterprise Library Core. Since the other application blocks were relying on the Configuration Management Application Block, they were modified to use the new components in the .NET Framework instead. You can find more information on this subject here.

The new classes providing the configuration management functionality still live in the System.Configuration namespace, but they are compiled into a separate assembly named System.Configuration. So in order to use the new bits, you need to add a reference to System.Configuration.dll.

Posted by Mehran Nikoo | 1 comment(s)
Filed under: