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:
… which shows a page with…
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:
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:
Great! Well, no, there are two problems with that…
The first problem is that external users will use the other 3 Contact fields. Ideally, I’d like my page to not need all 4 fields.
The other problem is, our customer is really keen that the Contact section show a user’s Profile Picture (because what you need at the bottom of a long page full of bureaucratic process is a picture of a scary co-worker). Anyway, we have users, they have pictures, we aught to be able to show them all together.
Well, I tried dropping a ‘Contact Details Web Part’ onto the page – directly on, not into a WebPartZone. This gave me the look I wanted, and better still, it appeared to be reading the data from my Contact field!
Cool! And yet strange – how was this happening? I took a look in the code, and noticed that the code seemed to reference the ContactFieldControl. Not much information about that control.
Oh well, I can live with the unknown – provided it works. So, what did I end up with? Well, the Contact field had a nice editting experience, but the display wasn’t what I wanted. The ContactFieldControl had a nice display, but didn’t do anything in edit mode. A plan formed – I put the Contact field into an EditModePanel (along with my page roll up image) and would use it to update the displaying web part:
And in Display mode? Well, that Contact field wouldn’t show! (I’d changed the contact for the page for the screenshot below…)
Hurrah! Problem solved? Not quite. What about manually entered contacts – that is, non-SharePoint user details? Well, I went and filled in those details to see:
And when I saved the Page Settings, SharePoint errored:
Not really the result I was looking for. It appears that there is an internal error in the ContactFieldControl. A sneaking hunch led me to try again, but without specifying a user image:
This worked:
Now, what about linking/mailing this contact? Well, the Menu would open correctly, and you could email him:
But, if you try to view his My Site, or click on him to go to it you get:
Well, that’s hardly surprising – he isn’t a SharePoint user, so he won’t have a My Site.
All in all, I reckon that the ‘Manual’ contact is unlikely to be something that happens at this particular customer, so I’m happy enough to use this technique. I’d love to know what ‘tells’ the ContactFieldControl what the Contact field for the page is. I mean, what if I’d another field I wanted to use? How would that work?
This is nicely elegant solution.
It saved me creating of my own control. Thank you Andy.
I’ve experienced one constrain, that contact person must be specified, otherwise the control behaves a bit unfriendly. When a link with a text “Click here to add or modify a contact” is displayed, which leads to error. Do you know solution for this? I also wonder how did you sneak around the manualy edited “Enter contact information”.
Thanks in advance for any hint,
Ondrej
Hi Ondrej,
Yeah, I found that constraint too. I snuck around that one by programmatically setting the Page Contact to the creator of the page – I could do that in the feature I was writing. You could do the same with an event receiver attached to the Pages Library, I’d guess. But I never really did resolve that one.
And the manually entered user data? Well, I never resolved that one, either. Quite simply, that customer never does that, not least as the page contact is shown in the edit box on the page – I doubt they even use the “Page Settings”.
Andy
well done and well written. this is the solution i needed. merci.