Thanks!

Updating Site Title (SPWeb web.Title) programmatically

Scenario:

Sharepoint 2010 (Server or Foundation) is installed, and you also have installed one or more language packs.

You update the SPWeb web.Title programmatically (web.Title = “New Title”, web.Update();) in C#, but the title is not updated in your browser. This will happen if your Sharepoint installation for example is English (1033), and your site is created in Norwegian (1044). It doesn’t matter if the installation language isn’t activated as a possible display language for your site, your updated title will only show when you choose the installation language as Display Language.

If you debug, you will se that the property web.Title is updated, but this is not what is shown in the browser. If you search further through the site’s properties when debugging, you will find a property called m_strTitle that holds your original title and obviously needs to beed updated. But, you cannot update this property directly.

So, how do you update the title in all Display Languages of the site?

SPUserResource resource = web.TitleResource;
foreach (CultureInfo culture in web.SupportedUICultures)
{
Thread.CurrentThread.CurrentUICulture = culture;
resource.Value = "New Site Title";
}

This also applies to for example web.Description, but not web.Name (which also is basis for the Site’s URL).

Remember to call web.Update, and ofcourse to do a web.Dispose if you are not using Using:)

4 comments to Updating Site Title (SPWeb web.Title) programmatically

  • Hello,

    Thank you for your blog post about CU upgrade failure. I also had upgrade failure at 10% with December CU and i tried your command successfully. But do we know the origin of this failure ? I upgraded 6 other farms as well but have systematically this problem at 10% if a choose the psconfig GUI to do the upgrade.

    Thank you,

  • This could be a little more elegant:

    foreach (System.Globalization.CultureInfo culture in misitio.SupportedUICultures)
    {
    resource.SetValueForUICulture(culture, args[2]);
    }


    This can avoid having to change the culture set for the thread.

  • Thanks for the feedback, I haven’t tried this but what you write seems more compact and to-the-point.

  • Welcome! is easy to improve what is well done :)

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>