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…
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…
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:
<SharePoint:ProjectProperty Property="Title" runat="server"/>
<SharePoint:ListProperty Property="Title" runat="server"/>
<SharePoint:ListItemProperty Property="Modified" runat="server"/>
<SharePoint:FieldValue FieldName="Modified" runat="server"/>
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:
- 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 🙂