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…

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!

contact-details-web-part

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.

code-sample

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:

page-contact-details-web-part-and-contact-field-working-together-edit-mode

And in Display mode? Well, that Contact field wouldn’t show! (I’d changed the contact for the page for the screenshot below…)

page-contact-details-web-part-and-contact-field-working-together-view-mode

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:

manually-entered-contact-details

And when I saved the Page Settings, SharePoint errored:

error-if-there-is-a-picture-url

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:

manually-entered-contact-details-without-picture

This worked:

manual-contact

Now, what about linking/mailing this contact? Well, the Menu would open correctly, and you could email him:

manually-entered-email-address

But, if you try to view his My Site, or click on him to go to it you get:

user-not-found

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?

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

3 thoughts on “Show a Page's Contact and Picture on a Publishing Page

  1. Ondrej says:

    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

  2. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.