Thursday, September 19, 2013

SharePoint - Setting Site Title programmatically not working

Recently, I got request to make a small script that could change name of SharePoint Site programmatically from c# code.

Well, the code for doing that is extremely simple, I found it on Microsoft's web page:



using(SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    oWebsite.Title = "New Website Name";
    oWebsite.Update();
}

The code executed with no errors, but no change to the site title was made.

It is annoying how such small portion of code can cause trouble.

This code works perfectly if your site's language is default language - English for example. But, if you have more than one language installed and you created your site using different language template - for example Croatian, then this code will not work.

To change you site title, you must change title for all languages:

SPUserResource userRes = web.TitleResource;
foreach (CultureInfo item in web.SupportedUICultures)
{
     userRes.SetValueForUICulture(culture, "My custom site title");
}


1 comment: