in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Tech MOSS Team

Inconvenient SharePoint 2007 localization

SharePoint 2007 has built-in support for Resource files helping you achieve localization. Using these files you are able to set localized labels for the resources being provisioned. Furthermore you are able to use Resource files within your assemblies to support localization on run time. Yet there is something wrong with localization in SharePoint 2007...

One of the requirements for the project I'm currently working on is that the solution must be built on top of Dutch version of SharePoint 2007. Just to spare myself some unpleasant surprises I have decided to use that particular locale from the very beginning of the project. I got really surprised when I got a vague exception in Dutch while activating one of the Features we deliver standard with our projects. After a little research I have found out the reason of the exception: I have tried to access the Master Page Gallery using SPWeb.Lists["Master Page Gallery"]. However, since I was working with the Dutch locale it didn't exist. There was that strange thing called "Galerie met basispagina's" instead.

Looking for a solution I took a look at the SharePoint object model. SPListCollection gives you three ways to obtain a list: you can use either the ID (GUID), list index (???) and the list name. It's not really convenient as all these methods use parameters which refer to variable values. Of course you could try loading the Dutch resource file shipped with the Dutch language pack for SharePoint and then retrieving the "Galerie met basispagina's" string - it just seems a little too much to me. Why you can't get a list using the only constant information like... it's URL?!

If you take a look at the SPList class you will find that there is no Url property. Instead there is this thing called RootFolder (SPFolder) which does contain a Url property which contains the site relative url of the particular list - _catalogs/masterpage in case of "Galerie met basispagina's".

Recently I have started working with Extension Methods. Briefly: they allow you to add a custom method to an existing type, for example: SPListCollection.GetListByRootFolderUrl(string rootFolderUrl). Personally I think it's a great possibility to extend existing object models allowing you to work with the code in a more natural way.

The solution

public static SPList GetListByRootFolderUrl(this SPListCollection lists,
string rootFolderUrl) { SPList list = null; foreach (SPList l in lists) { if (String.Compare(rootFolderUrl,
l.RootFolder.Url,
StringComparison.CurrentCultureIgnoreCase) == 0) { list = l; break; } } return list; }

The solution is really straight-forward: just iterate through all available lists in the SPListCollection and return the one which has the RootFolder Url which corresponds to the rootFolderUrl parameter. If you implement the above method in a public static class, you will be able to use it like SPWeb.Lists.GetListByRootFolderUrl("_catalogs/masterpage") what will solve your SharePoint 2007 localization problem... this time.

Comments

 

MajsRoger said:

Have you finished this tool yet? I'm sitting on needles here waiting for your util to be released! :)

February 10, 2008 3:57 PM
 

Links (2/10/2008) « Steve Pietrek’s SharePoint Stuff said:

Pingback from  Links (2/10/2008) « Steve Pietrek’s SharePoint Stuff

February 10, 2008 6:09 PM
 

Waldek Mastykarz said:

Unfortunately I haven't managed to publish the utility before going to ODC. It has to do with two things: reflected code is crappy and has to be cleaned up, plus I want to find a better approach than SelectSingleNode for retrieving the list information. It all takes some more time than expected yet, the tool will be available really soon.

February 10, 2008 10:16 PM
 

Cliff Green said:

Does using the SPSite.GetCatalog(SPListTemplateType.MasterPageCatalog) not get you there?

July 10, 2008 3:29 PM
 

Waldek Mastykarz said:

Yes, you're absolutely right Cliff. Unfortunately it works with the built in Libraries and Lists only. You could of course use your own class to keep the GUID's of self created lists, but I might think a few scenario's when it wouldn't be possible.

July 11, 2008 1:14 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

About Waldek Mastykarz

Waldek Mastykarz is a Dutch SharePoint 2007 developer specialized in Web Content Management solutions in Microsoft Office SharePoint Server 2007, web standards and accessibility.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts