Show Site, List or Item information on Pages

I’ve seen a few questions on Twitter over the last few weeks about how to show properties from Sites or Publishing pages within pages. Actually, this is very easy.

Obviously, if you’re working with Publishing Pages, you’ve got all your publishing controls, which you can see in SharePoint Designer…

publishing-controls-in-SharePoint-Designer

But what about site information, such as the Site Title? Or other Page Information, such as the Last Modified time? Well, I want to introduce 4 other controls – ProjectProperty, ListProperty, ListItemProperty and FieldValue

These controls are also available in SharePoint Designer…

sharepoint-web-controls

They allow you to display properties from the site (for some reason called a ‘Project’), list or list item. For example, here I’m showing information on a publishing Page, so the page is an item in the Pages library, of a site called Pub, using this code:

<b>Site Name:</b>
<SharePoint:ProjectProperty Property="Title" runat="server"/>
<b>List Name:</b>
<SharePoint:ListProperty Property="Title" runat="server"/>
<b>Item Date:</b>
<SharePoint:ListItemProperty Property="Modified" runat="server"/>
<b>Item Date:</b>
<SharePoint:FieldValue FieldName="Modified" runat="server"/>

This displays:

sharepoint-controls-display

Great! Note, however, that the FieldValue control adjusts for my local time (UTC+1 right now), while the ListItemProperty does not.

But what properties can I use? Well, ProjectProperty and ListProperty do describe at least some of their properties, though I don’t know if all these work, or if there are more. The code is a bit puzzling when I use Reflector on them. Still, for ListProperty I think that Title, Description, RelativeFolderPath and ItemCount all sound useful, and for ProjectProperty I like the look of Title, Url and SiteUrl.

What about ListItemProperty and FieldValue, though? Well, sadly, it don’t tell us what options they have. A bit of experimentation shows that ListItemProperty can get:

  • ID
  • Title
  • Created
  • Modified
  • FileSizeDisplay
  • ContentType
  • PublishingPageLayout
  • PublishingPageContent
  • Comments (Description)
  • Author (Created By)
  • Editor (Modified by)
  • Edit (The Edit Item button)

There may be more – and clearly we’re able to get some custom properties. I also tried the FieldValue too, and got much the same results – although datetimes are all in UTC zone, and the file size was in bytes, rather than kilobytes.

Now, I demonstrated all this on a publishing page for a reason. A publishing page is a list item, and exists in a list. What of non-publishing pages, such as default.aspx for a team site, or list forms/views?

  • All these pages exist inside a site, so they can all use ProjectProperty items.
  • Pages in a List, such as Views or list forms (Add/edit/display) can use ListProperty controls – and do, out of the box. Default.aspx doesn’t live in a list though, so it can’t use the ListProperty control; it has no data to retrieve.

Sadly, there doesn’t seem to be a ‘FileProperty’ type control for getting information for files like Default.aspx. ‘Course it wouldn’t be too hard to write one 🙂

Advertisements
Show Site, List or Item information on Pages

7 thoughts on “Show Site, List or Item information on Pages

  1. Jason says:

    I find these properties to be potentially quite beneficial. Perhaps you can assist with an issue I am facing. I am currently in need of the to be stored into a variable for later use. This is within the NewForm.aspx for a new list item.

    I can get the property to display just fine in the title, but cannot add it to a redirect, as desired. Thoughts?

  2. Not sure I understand your description, or quite what you mean by ‘redirect’? I think some words might be missing in there?

  3. Cris says:

    ..the easy way to add data to standard edit and display list forms! Well done. It helped me with the last few steps to finalize my forms.

  4. Brett says:

    THANK YOU!!!!

    So hard to find a website with this information so simplified. Site Bookmarked 🙂

  5. Anon says:

    I am trying to use but when I refresh the page, it shows “403 forbidden”. Any idea why? All of the other Project Properties are working as expected.

  6. Daniel says:

    How can I display FieldValues (from say List called ‘Directories’) on a different SharePoint Wiki-type page? Thanks

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.