Putting Custom Web Parts in ONET.xml

So yesterday I was trying to add a content editor webpart to a page I was deploying through ONET.XML. I wondered how to add custom web parts, and how you’d know what the XML for them was.

Turns out it isn’t very hard. An example:

<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<type name="SourceCode.Solutions.GenericCaseWebParts.CaseSSRSReportViewer" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
<property name="TitleUrl" type="string" />
<property name="TitleIconImageUrl" type="string" />
<property name="ReportServerUrl" type="string">http://vm-moss:8088/ReportServer</property>
<property name="Parameters" type="string">&lt;ReportParameters&gt;&lt;Parameter Name="CaseId" MultiValue="false" Value="[Case Id]" /&gt;&lt;/ReportParameters&gt;</property>
<property name="ChromeState" type="chromestate">Normal</property>
<property name="Title" type="string">Context Info</property>
<property name="ReportPath" type="string">/Reports/Case Details</property>
<!-- Snip -->

As you can see, at the top we define the class to use, then we set various properties (I’ve trimmed that set quite a lot). But how did I get the XML? Well… I set the web part up in SharePoint and exported the web part to a file; this was the XML I needed to put into my ONET.xml. Copy and paste… job done.

Putting Custom Web Parts in ONET.xml

Putting CEWP into a page in ONET.XML

When you provision sites you can provide various pages (normal pages, not just publishing ones!) However, what if you want to put web parts onto those pages?

Well, you could build multiple pages for your different site configurations. Or you could use a feature receiver to add it programmatically. Or, you could add it via your site configuration. Continue reading “Putting CEWP into a page in ONET.XML”

Putting CEWP into a page in ONET.XML

Roll up content by content-type

Pointed out to me by a colleague (ages ago!) – Ton Stegeman’s ‘Content by Type‘ web part. A good way of rolling up content of diverse types, without lots of XSL. If your content type structure is right, may well be other ways of doing this (the content query web part and data view may work) – but this is quite a nice looking tool, and simpler. Need to download and have a play sometime soon.

Roll up content by content-type

Polling Web Part by Phil Wicklund

I’ve just downloaded (from codeplex) and had a look at the Polling Web Part by Phil Wicklund. We’ve a customer who wants exactly this sort of functionality – surveys are too heavy weight; they just want a little radio-button panel. That’s what the Polling Web Part does:


Cool. And it shows it’s results as:


Hmm. So how does it store it’s data? Well, that seems to me a little strange – each poll, options and responses are a single row in a list:


Bit strange if you ask me. Some consequences of this are that:

  • You can’t have more than 5 options
  • You can’t be sure that someone doesn’t respond twice (although it appears that a cookie is set to prevent that from being too easy).
  • Curiously, you can’t tell the web part to point to a particular poll question. It appears to always point to the latest. It’d be nice to have a drop down to select the poll in the Web Part Toolbox menu.

I must confess that I’d have considered having different polls in different lists, and reading the values available out of a Choice column on that list. Each response would be a List Item, so you’d know if someone has already created one. Still, Phil’s approach is probably quicker to process.

Other thoughts – well, it’d be nice to have bar chart rendering too.

All of which is, I must point out, quite picky. It does what it does well, and is free, and the source code is available; I may try and have a look at that at some time.

Polling Web Part by Phil Wicklund

Missing Web Part Titles in Search Center Pages

I just had a really weird error – I’d built some search pages for a customer. There was a custom results page, and a custom ‘Advanced Search’ page. When I went into Edit mode, to change the web parts, they didn’t have a title bar – including the ‘Modify this web part’ link. WTF?

Well, they’d been customized using SharePoint Designer, so I figured I’d copy their code from the customer system into a VM of mine, and check that the pages broke on my system. They didn’t. WTF x2 ?

So, the page page code, inside the same master page, in two different systems works differently. To check I wasn’t going nuts, I tried a WinMerge compare on the two files – and found this chunk of XML in my non-working version on the customer site:

<!--[if gte mso 9]><xml>
<o:PublishingContactPicture msdt:dt="string" dt="string">, </o:PublishingContactPicture><o:PublishingContact dt="string"></o:PublishingContact>

Yes, although I’d cut and pasted the code, it was different. I came to the conclusion that this code is created or used by SharePoint Designer itself. I decided to delete it, save the changes to the customer’s page, and refresh my pages. It worked; now when I edit the page, lo, there are titles and the ‘Modify this web part’ menu. I have no idea what this XML is about, but I’m about 70% confident that it’s the culprit. I reckon that there’s a 30% chance that it was just being customized in SharePoint Designer again that fixed it, but I couldn’t see anything else related to the code that was likely to be a problem.

Missing Web Part Titles in Search Center Pages

When saving data into Web Part Properties, remember [Serializable]

So, previously I’d described using a Web Part Property of an ArrayList to store a list of things. In that demo, I’d been just storing strings.

Well, my requirements got a little more complex, so I started trying to store my own objects in there – really, just objects storing data, no logic. However, when I added things to the property and ran .SetPersonalizationDirty() my data wasn’t saved. Worse, the values of other (unchanged) web part properties were lost! They kept coming through as null, rather than the values I’d set previously. There was no indication of error.

Well, here is Andy’s tip for folks who manage to forget the basics of C# development – don’t forget the [Serializable] attribute.

Without it, my data objects can’t, well, be serialized – that is, saved. So it’s unsurprising that my data wasn’t saved! What was unfortunate and threw me off the sent was that there were no errors shown, and that wiping out the values of the other web part properties did rather thrown me off the scent! I guess I was really having an off day when I wrote that…

When saving data into Web Part Properties, remember [Serializable]

Style individual web parts

Like Heather Solomon, I’m sometimes asked about styling individual web parts differently to the rest. I didn’t know of any way of doing this; instead, we’d typically style particular web part zones differently, but this meant that all web parts in that area looked differently.

Well, Heather has now posted ‘Controling single web parts with CSS‘. Neat. I didn’t know you could do that attribute selection.

The downer about this technique is that you have to set a DOCTYPE – and I can see that causing all sorts of grief as stuff breaks… …so it’s probably not something you’d do unless you’re building reasonably custom master page.

Style individual web parts

Storing Data within Web Parts

We have a customer who wants a custom web part similar to the Summary Links web part – that is, editors can add links in this web part (along with some other metadata). For various reasons, a ListView web part and a Links library weren’t what they were after.

Now, the Summary Links web part seems to me to be a bit unusual. Most web parts access and use data stored elsewhere – lists, web services, databases, etc.. However, the Summary Links web part stores it’s data internally. How does it do that, and can I do the same? Continue reading “Storing Data within Web Parts”

Storing Data within Web Parts

Content Roll-up options – Conclusions

So, what what content roll-up web part to choose? Well, typically (for SharePoint) it depends.

Bamboo’s List Roll-up Web Part is the most feature rich, but a bit tricky – certainly it’s a bit too complex if you’re wanting to allow users to set up their own roll-up. The use of CAML is also a big no-no for allowing basic users to set up their own. It’s a shame; it really is let down by this complexity, although it’s still simpler than using SharePoint Designer.

Using the Dataview Web Part directly has the same problem as Bamboo’s List Roll-up – complexity. It also requires SharePoint Designer. It’s harder to generate the Data View Web Part, but to be honest (given that you can do the same things as Bamboo’s List Roll-up web part) I suspect that most organisations would be fairly willing to live with that.

For me, it’s main problem is that it doesn’t pick up new lists automatically; you have to modify the data view web part to add the new lists. For that reason, I think you can only use this approach when you have a fixed set of lists to aggregate over.

The Content Query Web Part is pretty good, and there is a reason that it’s so often discussed in SharePoint Solutions. The web part itself is fairly straight forward to use – but using custom metadata in the display is a bit too complicated. Again, I think this solution is out of the range of the ability of typical users. I don’t like the lack of pagination options, either.

Lightning Conductor is the only one of the web parts that struck me as being simple enough that a non-technical person would be able to set up and use for content roll-up. It had many of the more complex features that we’ve seen (e.g. using XSL for formatting the results), but you didn’t have to use them, and the user interface exposes things that seem missing from the CQWP – like the ability to select the fields you want in the display! I’ve got to say, this is my favourite of the solutions I looked at.

So which one should you use? Well, as I said, it depends. The main factors involved seem to be:

  • Are you wanting to aggregate across site collections?
  • Are the source lists fixed, or will they be changing?
  • Will the roll up be configured by technical or non-technical staff?

I guess you weigh those up and take your choice.

Edit: One questions I was asked was if it’d be difficult to write your own. Well, there’s no reason why you couldn’t; with the SPSiteDataQuery it wouldn’t even be hard. Programming around the configuration would take longer, and as we’ve seen, this can make a big difference to the usability of your solution. What I would observe is that both the 3rd party solutions were pretty cheap; it’d be diffult to write your own for as small a cost.

Edit 2: A good post on when to use the CQWP vs the Lightning Conductor Web Part from Lightning tools…

Continue reading “Content Roll-up options – Conclusions”

Content Roll-up options – Conclusions

Content Roll-up options Part V – Bamboo's List Roll-up Web Part

And the final content roll-up web part I examined is Bamboo Solutions List Roll-up Web Part.

This web part is a little strange; indeed, I’m not sure how to describe it. As I understand it, basically it’s a web part to generate a data-view web part, and add it to the page. Sound strange? Well, it is a little bit. Let’s have a look:

Web Part for generating other web parts

As you can see, this is a big web part on page. It’s user interface is much more complicated than the Lightning Conductor. I couldn’t help but notice that to do filtering by metadata column values appears to require writing CAML – which really is a bit much for many users.

This web part then generates an output Dataview Web Part:

Generated Dataview Web Part

(In that example, it’s only aggregating from one list – ‘cos I forgot that gave my lists different names, and then told the view to roll-up by list name).

So, it’s advantages:

  • Can consolidate across Multiple Site Collections (which isn’t possible through the Out-of-box options)
  • Can consolidate a single site collection, a site and it’s subsites or a specific list.
  • Can also consolidate sibling sites – which isn’t something I’ve seen elsewhere.
  • Can filter by list type
  • Can filter by content type or meta data fields
  • Can Group results
  • Has user definable sorting
  • Has Pagination of results
  • Fine control over caching

And it’s disadvantages:

  • More complex to use
  • More complex user interface
  • Probably requires writing CAML
  • Costs money (though I think is still a bargain compared to developer time)
  • Could be a tough sell to customers (“But SharePoint already has the Content Query Web Part“)

In short: Probably the most powerful and feature rich of the web parts, but not as easy to use as some of the others. Really, more of a developer tool than a user tool.

So, on to the conclusions…

Continue reading “Content Roll-up options Part V – Bamboo's List Roll-up Web Part”

Content Roll-up options Part V – Bamboo's List Roll-up Web Part