I’ve been updating some of my demos for the upcoming DC SharePoint Best Practices Conference (http://www.bestpracticesconference.com/). Basically, I have a session that shows different approaches to common document generation scenarios that customers have expressed an interest in. I will show why you want to be building these out with SharePoint and why you want to use some of the latest tools to help. These tools are things like the new Visual Studio Extensions for WSS, the new Open XML SDK, and the Word Content Control toolkit. Some of the demos in my session (on the first day of the conference) were solutions that I first proposed in my book: Pro SharePoint Solution Development. Those solutions were built on (gasp) VS.NET 2005 and the Packaging API which was brand new back then. For those of you who have been looking for an update, here you go. Here are some download links to updated projects:
A web part for building a PowerPoint presentation server-side:
A new feature that merges SharePoint list data into a Word document template:
A new feature that supports the splitting of a document into discrete sections and then merged back:
Just a reminder that all of these solutions are really just demo code and should have a lot more error handling and testing. But it gives you a really good starting point for your own solutions. The biggest difference with these new projects is the use of the Open XML SDK which gives you an object model to work with instead of coding nasty XML. Here is an example of an old code snippet that opened up a PowerPoint template and located the slide parts:
Using pptPackage As Package = Package.Open(fileStream, FileMode.Open, FileAccess.ReadWrite)
' Get the main document part (presentation.xml).
For Each relationship As PackageRelationship In pptPackage.GetRelationshipsByType(documentRelationshipType)
documentUri = PackUriHelper.ResolvePartUri(New Uri("/", UriKind.Relative), relationship.TargetUri)
documentPart = pptPackage.GetPart(documentUri)
' There is only one document part. Get out now.
' Manage namespaces to perform Xml XPath queries.
Dim nt As New NameTable()
nsManager = New XmlNamespaceManager(nt)
' Iterate through the slides and extract the title string from each.
Dim xDoc As New XmlDocument(nt)
Dim sheetNodes As XmlNodeList = xDoc.SelectNodes("//p:sldIdLst/p:sldId", nsManager)
And see how this changes with the new SDK:
Dim presDoc As PresentationDocument = PresentationDocument.Open(fileStream, True)
Dim presPart As PresentationPart = presDoc.PresentationPart
Dim presentation As DocumentFormat.OpenXml.Presentation.Presentation = presPart.Presentation
If (Not (presentation.SlideIdList) Is Nothing) Then
' Get the title of each slide in the slide order.
For Each slideId As SlideId In presentation.SlideIdList.Elements(Of SlideId)()
Just a reminder that you need these add-ons to VS.NET 2008 to work with these projects:
Visual Studio Extensions 1.3 March Preview:
Open XML Format 2.0 SDK April Preview: