Modify a Word 2007 Open XML document via C#

Interesting problem that I came across here…A client requested that their system was to have the ability to load in a Word 2007 Document, perform some text manipulation routines and save the document back to the server.

Firstly, you can rename a docx document to docx.zip and you can extract all of the files in the zip file that build the foundation of the Open XML document.   Not bad!

Here is the code that I used to open a Word 2007 document, do some manipulation and save the file.

using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(newPath, true))
{

string docText;
using (var sr = new StreamReader(wdDoc.MainDocumentPart.GetStream()))
{
docText = sr.ReadToEnd();
}

docText = RegExpReplace(“{REPLACETEXTHERE}”, docText, “With this value”);
using (var sw = new StreamWriter(wdDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
sw.Write(docText);
}

}

The WordprocessingDocument classes are part of the Open XML Format 1.0 SDK available from Microsoft.

This beats having to do the old way of importing Office API Dlls via COM to load and write word documents!

References:

http://msdn.microsoft.com/en-us/library/documentformat.openxml.packaging.wordprocessingdocument.aspx

A CMS that integrates into ASP.NET MVC

Here is a open source CMS called N2 that provides a CMS framework to build web applications on using the ASP.NET MVC Model.   Its a very basic CMS, but it provides all the core functionality including Pages, Articles and a .NET Permissions Model (it also has some add ons and allows developers to contribute their own add ons).   They have lots of documentation and useful examples on how to work the CMS with MVC.   Very cool stuff!

References:

http://n2cms.com

The specified ‘@subsystem’ is invalid

If you get the following error:

Create maintenance plan failed.

The specified ‘@subsystem’ is invalid (valid values are returned by sp_enum_sqlagent_subsystems). (Microsoft SQL Server, Error 14234)

Just install Integration Services (just a little job…) and reboot.

References:

http://support.microsoft.com/kb/909036/en-us