Web Parts on SharePoint 2010 Wiki Pages.. marriage made in heaven

 

This is something that really confused me the first time I did it (by accident actually), but you can indeed drop web parts directly into Wiki Content.

 

Let me just repeat that in case you missed it:

You can drop web parts directly into the HTML of Wiki content

 

There is no concept here of web part zones, or ordering .. You can literally seamlessly have them embedded in the HTML!

 

This of course means great things for allowing dynamic page content to truly flow, with dynamic web part content sitting seamlessly side-by-side with your Wiki content (hopefully this also means the death of over-complicated Page Layouts to accommodate hundreds of Web Part zones .. And also hopefully the death of the Content Editor web Part!)

 

To add the web parts is really easy, it uses the new SharePoint 2001 "Ribbon" interface, and you just literally just insert web parts the same way you would with tables, images, or any other type of content.

 

It actually achieves this by using a hidden web part zone (called the "WP Zone") which the Wiki uses to store the web parts (and retrieve the web part properties.)

 

Now, let me just hit you with another big one: Web Parts now support content versioning.

 

Again: Web Parts will now roll-back along with page versioning! So when you restore a version of a page, the Web Part properties in that version will also work!

You don’t need extra code for that, it "just works" (very very cool!)

 

How can I do this programmatically?

There are 2 different methods you can tackle for this:

 

The "WikiEditPage" class includes a method called "InsertWebPartIntoWikiPage". This is a ron-seal method (it does what is says on the tin!).

 

Alternatively you can also "roll your own".  Web Parts are identified in the Wiki HTML through a DIV placeholder with some specific GUID references. So you can hand-crank this HTML content and drop it into your wiki page.