Export (0) Print
Expand All

SPNavigationNode.TitleResource property

Gets an object that represents the SPUserResource that can be used to get or set translations for the navigation node title.

Namespace:  Microsoft.SharePoint.Navigation
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPUserResource TitleResource { get; }

Property value

Type: Microsoft.SharePoint.SPUserResource
An object that contains the user resource that can used to get or set the translations for the navigation node title.

This property is the source for the string returned by the Title property, which returns TitleResource.Value. The value that is returned by this expression can vary depending on the value of the CurrentUICulture of the current thread. For more information, see the SPUserResource.Value property.

The following example is a console application that creates a new navigation node that links to the Announcements list and adds the node to the Quick Launch area of a Web site. The application then iterates through the list of languages supported by the Web site's multilingual user interface and code copies localized values from the Announcement list's TitleResource property to the node's TitleResource property.

TipTip

If you have deployed resource files (.resx) with translations to support your application, then you do not need to set the TitleResource property as the example does. Instead, pass a resource expression to the SPNavigationNode constructor. For example, the following line of code constructs a node that links to the Announcements list:

SPNavigationNode newNode = new SPNavigationNode("$Resources:core,announceList", list.DefaultViewUrl);

In the string that is passed as the first argument, the character "$" indicates an expression, "Resources" indicates the type of expression, "core" is the name of a resource file and "announceList" is the name of the resource. Spaces are not allowed in resource expressions, so there is no space after the comma.

using System;
using System.Globalization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    web.QuickLaunchEnabled = true;
                    web.IsMultilingual = true;

                    SPList list = web.Lists.TryGetList("Announcements");
                    if (list != null)
                    {
                        // Create a navigation node pointing to the Announcements list.
                        SPNavigationNode newNode = new SPNavigationNode(list.Title, list.DefaultViewUrl);

                        // Add the node to the Quick Launch area.
                        SPNavigationNodeCollection quickLaunch = web.Navigation.QuickLaunch;
                        quickLaunch.AddAsLast(newNode);

                        // Copy translations of the list's title to the user resource for the node's title.
                        string localizedTitle;
                        foreach (CultureInfo culture in web.SupportedUICultures)
                        {
                            localizedTitle = list.TitleResource.GetValueForUICulture(culture);
                            newNode.TitleResource.SetValueForUICulture(culture, localizedTitle);
                        }
                        newNode.Update();
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.Read();
        }
    }
}
Show:
© 2014 Microsoft