Thursday, June 25, 2009

Check if SPList or SPView exists

One thing that the SharePoint team left out is a built-in way to see if a SPList or SPView exists.

So if you have the Dynamic library from ScottGu's Blog then you can setup an extension method or helper method with the following linq:

SPList

spweb.Lists.Cast().Any(list => string.Equals(list.Title, listName));

SPView

splist.Views.Cast().Any(view => string.Equals(view.Title, viewName));

both return a boolean

Monday, June 15, 2009

MOSS Search crawler not populating out of the box or custom metadata properties

One interesting issue we faced on my current ongoing project was that MOSS Search crawler would not popluate the out of the box or custom metadata properties, it would return results as if it was a HTTP crawl. This was only an issue on 1 farm, unfortunately this was the production farm, the UAT environment was working as expected.

After a colleague of mine searched the interent endlessly, finding others with the same issue but no answers, we logged a call with Microsoft and got a guy on live meeting who solved the issue in about 5 minutes.
When SharePoint creates the IIS Web Application it should place a HTTP Response Header called MicrosoftSharePointTeamServices with a version number as shown below:



In our case in production for whatever reason it did not create this header.
Adding the header manually got use up and running!

PortalSiteMapProvider randomly drops off pages

I built custom navigation for the http://nzte.govt.nz website using the PortalSiteMapProvider.
This is a powerful ally in the SharePoint Publishing Site world as it handles caching and security trimming. It also means that when you use one of the built-in instances of the PortalSiteMapProvider like CurrentNavSiteMapProvider you can use the navigation edit menu under Site Actions->Site Settings to hide/show sites and pages, change the order and add new links.

One thing that was unexepected was that every now and then the PortalSiteMapProvider would not return pages. We had content editors showing us screenshots of the menu showing only sites. This was easy to replicate by pressing F5 repeatedly until eventually it would happen (around 20-40 refreshes).
Now by default the propoerty IncludePages is set to PerWeb, so in attempt to fix the issue I added IncludePages="Always" to the web config as follows:

<add name="CurrentNavSiteMapProvider" .... includepages="Always" dynamicchildlimit="0">

but this didnt help.

The answer is to set the IncludePages property in your code block when you are building your navigation as follows:


PortalSiteMapProvider psmp = PortalSiteMapProvider.CurrentNavSiteMapProvider;
psmp.IncludePages = PortalSiteMapProvider.IncludeOption.Always; //resetting as it sometimes drops off
SiteMapNode siteMapNode = psmp.FindSiteMapNode(elevatedWeb.ServerRelativeUrl);
List leve1ItemList = new List();
for (int i = siteMapNode.ChildNodes.Count - 1; i >= 0; i--)
{
leve1ItemList.Add(siteMapNode.ChildNodes[i]);
}
leve1ItemList.Reverse();
level1Repeater.DataSource = leve1ItemList;
level1Repeater.DataBind();
}


One other thing is to set the DynamicChildLimit in the web config as by default it only displays 50 and if you have over 50 items it can also cause unexcept results like not displaying anything at all. As you can see above I have set it to 0 which means it has no limits.