Life, the universe and whatever

Something to say about most things

Archive for the month “July, 2009”

SharePoint and Silverlight 3

Having accomplished some great results with version 2 of Silverlight in some of my SharePoint projects I have been wondering about version 3 as the implementation has changed somewhat.  Karine Bosche has very kindly gone to the trouble of blogging how to get your Silverlight 3 applications running in WSS 3.0 and MOSS 2007.  Time to roll up the sleeves and dive into all that new functionality!

SharePoint Property Hash Tables

Today I read another great article by Andy Burns entitled Control the RSS Feed Settings on an SPList via the API.  What I love about Andy’s posts are the way he describes the problem first and then how he goes about tackling them, he’s obviously not just a SharePoint specialist but also clearly a true professional when it comes to software development.  If you haven’t read Andy’s blog before I seriously recommend subscribing and then making yourself a coffee and taking a good look through his back catalogue.

Andy used his experience and a nifty tool from Codeplex called SharePoint Manager to inspect the RootFolder Properties HashTable of the SPList object and sure enough he found the settings.  When you’ve come across this concept once or twice it becomes a logical place to look for properties and configuration settings and Andy’s post reminded me of a similar scenario I found myself in recently.  I have a client who are building a new intranet based on WSS 3.0 and Search Server 2008 Express and they want it branded the same as their new internet site.  I created two master pages and a site definition and I wanted to add a Search Center when a new Site Collection is provisioned from the site definition.  That part was straight forward;

SPWeb searchSite = rootWeb.Webs.Add("search", "Search Centre", string.Empty, rootWeb.Language, "SRCHCENTERLITE#0", false, false);

When Search Server is installed a file called webtempsrch.xml is added to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML directory containing details of the template used to create the Search Center site, that is where the template name and ID are taken from to form the SPWebTemplate parameter “SRCHCENTERLITE#0”.

I then wanted to associate the search box found on most standard WSS 3.0 site pages (a.k.a. the small search box) with the Search Center results page rather than the standard /_layouts/OSSSearchResults.aspx page.  Through the user interface this is easily achieved by opening the Site Settings and selecting Search settings from the Site Collection Administration group.

image

On the Search Settings page simply select the first radio button to send searches to a Search Center and provide the relative URL.  However, I faced a similar problem to Andy and wanted to configure this programmatically when the site collection is provisioned.  A quick look at the SPWeb object model in the SDK didn’t reveal anything obvious and neither did searches on Bing and Google.  My next thought was the SPWeb Properties Hashtable so I took a look in there and found something that looked promising;

image

Using the AllProperties property of the SPWeb it is possible to set the value of the Search Center for the Site Collection as follows;

rootSite.AllProperties["SRCH_ENH_FTR_URL"] = "/search"; // Site Settings > (Site Collection Administration) Search Settings > Use custom scopes
rootSite.Update();

Post Navigation

Follow

Get every new post delivered to your Inbox.