SharePoint keeps amazing me, even after working more than 6 years with the product. The product is this big that’s it is almost impossible to know all. This is one of those things. I simply did see it before.
When working on a “Yet Another SharePoint Gem” as Robin Meure called it. I stumbled on the SPBuiltInFieldId class and SPBuiltInContentTypeId class. When retrieving information like the CreatedBy field (also known as Author) it is very useful. Also when checking whether a item is based on a out-of-the-box (OOTB) content type. See exaples below.
Update: in addition to both SharePoint 2010 Foundation classes SharePoint Server has ContentTypeId class and FieldId class. Both are part of the Microsoft.SharePoint.Publishing namespace. Thanks to Jeffrey Schmitz (@DJeffa).
Here an example for the extension of the SPListItem class to retrieve the Author:
public static class SPListItemExtentions
/// Gets the author of a list item.
/// <param name="item">Extended class.</param>
/// <returns>Returns the author of the list item.</returns>
public static SPUser GetAuthor(this SPListItem item)
string user = item[SPBuiltInFieldId.Author].ToString();
int userId = Convert.ToInt16(user.Split(';'));
Another example for checking the base content type:
SPListItem item = list.GetItemById(1);
SPListItem topic = item;
// If item isn't the dicussion topic, get topic!
topic = GetTopicItem(item);
Posted by Bram de Jager on June 24, 2011
Having issues with navigation after an upgrade from MOSS2007 to SharePoint 2010 using the publishing template? We did! After an upgrade the navigation returned errors instead of menu items. We encountered these issues when the Dutch language pack was installed, because the Pages library has been translated/renamed to “Paginas”.
Microsoft has provided a solution described in KB 2484317. The root cause of the issue is described as:
With Microsoft Office SharePoint Server 2007 we stored new Publishing Pages in a library called Pages. In SharePoint 2010 it has been translated to Paginas as the default for Dutch. The navigation code assumes that any changes from the default are noted in a specific property, which is not the case for upgraded Dutch sites that have been created with the 2007 default name.
The solution to this problem is pretty easy, a simple PowerShell script will restore your navigation.
$site = Get-SPSite("http://WebApplicationURL")
foreach ($web in $site.AllWebs)
Write-Output("web:" + $web.ServerRelativeUrl);
$pageslistid = $web.AllProperties["__PagesListId"]
Write-Output($web.ServerRelativeUrl +" doesn't have a pages list id set - skipping");
$pageslistguid = new-object System.Guid($pageslistid)
$pageslist = $web.Lists[$pageslistguid]
$pagesurl = $pageslist.RootFolder.Url
$pb = $web.Properties;
Write-Output($web.ServerRelativeUrl +" set pages list to " + $pagesurl);
Posted by Bram de Jager on June 6, 2011