Programmatically create pages – and Add Web Parts

I had an interesting problem recently with a Site Definition. I was trying to create a publishing page, which would not create as the correct content type. I still haven’t got to the bottom of why.

However, time was limited, and we were going to have to create a feature receiver to staple to our site definition anyway, so I had a look at creating a publishing page programmatically.

We needed a feature receiver as the customer wanted the home page of their site to have a ‘Search Box’ which would ‘Search this site’, but go to a custom results page in a Search Center. My plan was to use a Search Box Web part, configured to go to a custom results page, and to append the query term:

site: [url to site]

e.g. site:http://sharepoint/finance/

Naturally, you don’t know the URL of the site until the site has been created – so this web part would have to be created programmatically. Continue reading “Programmatically create pages – and Add Web Parts”

Programmatically create pages – and Add Web Parts

What do out-of-box pages do with their Breadcrumbs?

As I’ve described before (and repeatedly bemoaned!) some page layouts hide the page level breadcrumb and display their own. Worse – they don’t all do this in the same way! All of this continues to feed my idea that you shouldn’t use any of the OOB publishing sites if you can help it.

However, sometimes we don’t have that luxury (i.e. I’ve never had that option) – so what do those crazy out-of-the-box page layouts do with their breadcrumbs? Well, Martijn Molegraaf has been kind enough to provide a chart. Nice one. And I feel your pain.

What do out-of-box pages do with their Breadcrumbs?

Out-of-Box Publishing Page layouts suck too

So, might not be news, but SharePoint’s out of box Page Layouts suck. I’ve already described how the page layouts have an image on branding, introducing styles to change the navigation, etc.. This has led me to the conclusion that you shouldn’t use the out-of-box publishing sites – start from a minimal publishing site, and build from the ground up.

But what of customers who have naively thought that, I don’t know, a Collaboration Site Template might be a good template to use for the collaboration site? Well, this is the problem I’ve got now; a customer has used the out-of-box page layouts extensively, and now wants the styles of the text and so on to be consistent. How can I do that? Continue reading “Out-of-Box Publishing Page layouts suck too”

Out-of-Box Publishing Page layouts suck too

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:

question

Cool. And it shows it’s results as:

results

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:

polls-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

Linking list data and summing over it with XSL and the Dataview Web Part

Thrilling title, eh? So, previously I’ve talked about merged lists in the Dataview web part. This time, I was after something slightly different – rather than merging two lists, I wanted to join them.

Joining is pretty easy, actually, but the process is a little bizarre. I ended up using the post ‘Performing Joins with SharePoint Lists‘ by Sahil Malik. The thing that confused me was that when I was I expected to provide the ‘keys’ of my lists when I created the new Datasource – but actually, you define it when you insert your ‘joined subview’.

Anyway, the scenario was that there are customer purchases for ‘Credits’ to do things. Operatives then do things for them, and these actions subtract time off those pools of credits. The need was for a way to:

  • Record purchases of pools of credits. Customers may purchase multiple times, but under different agreements (or invoices, or whatever)
  • Record actions and the number of credits that they cost
  • Remaining total.

I solved this with a Dataview web part, and two lists. Continue reading “Linking list data and summing over it with XSL and the Dataview Web Part”

Linking list data and summing over it with XSL and the Dataview Web Part

SharePoint Designer – grrr….

SharePoint designer is so like a wife – I love it to bits, sometimes I hate it, and I fervently hope for a cuter version in the future! No, I’m kidding.

But SPD currently has this persistence in adding a   in front of my page’s title field. I don’t need that non-breaking space. I don’t want that non-breaking space. But I keep deleting it, and Designer keeps adding it back in.

For me, it’s a sign one of the two big problems with SharePoint Designer – robustness. When I’m in Visual Studio, I’m comfortable; it’s pretty reliable, normally, and behaves in ways I understand. Even the things that can blow it up are pretty well understood. Much as I hate to admit it, I do think that the reason that C# won out over Java was simpler, robust tooling – Visual Studio.

However, with SharePoint designer all sorts of weird stuff happens… Continue reading “SharePoint Designer – grrr….”

SharePoint Designer – grrr….

Deploy Publishing Pages and Content Types as a feature

Aka “CAML is the bastard spawn of Satan”.

So, I’m writing a site definition to create a Publishing site. This is a bit of a first for me. One of the things I want to do is deploy a new Publishing Page Content type, and associate some layouts with it.

I started by following Andrew Connell’s instructions for a Minimal Site Definition (as in his book). This all seemed to go pretty well; testing created a new, minimal site.

Next up I wanted to deploy the Content Type and associated page layouts. Well, there wasn’t much information in his book on this – like him, I’d figured I’d write a separate Feature for deploying just the content type and page layouts – but there was very little information in his book about this. Continue reading “Deploy Publishing Pages and Content Types as a feature”

Deploy Publishing Pages and Content Types as a feature

Show a Page's Contact and Picture on a Publishing Page

So, one of our customers is really keen that the new Page Layouts I’m writing show the page’s contact on the page. For those of you who perhaps haven’t had need to use this, the Contact field is a standard field on Publishing Pages (i.e. the Page content type). You can interact with it via the page settings:

page-settings-on-a-publishing-page

… which shows a page with…

page-settings-for-contact

These fields are to allow you to select another SharePoint user, or manually enter someone’s details (if they’re not a SharePoint user!) Further, these fields are available in SharePoint designer:

contact-page-fields-in-sharepoint-designer-toolbox

So this looks like it’s shaping up to be a very brief blog post. Open up SharePoint designer, edit the page layout, drag the Contact field onto the page. With that, we get:

contact-field-as-displayed-on-page

Great! Well, no, there are two problems with that…

Continue reading “Show a Page's Contact and Picture on a Publishing Page”

Show a Page's Contact and Picture on a Publishing Page

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:CustomDocumentProperties>
<o:PublishingContactPicture msdt:dt="string" dt="string">, </o:PublishingContactPicture><o:PublishingContact dt="string"></o:PublishingContact>
</o:CustomDocumentProperties></xml><![endif]-->

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