共用方式為


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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public ReadOnly Property TitleResource As SPUserResource
    Get
'Usage
Dim instance As SPNavigationNode
Dim value As SPUserResource

value = instance.TitleResource
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.

Remarks

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.

Examples

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.

Tip

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("https://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();
        }
    }
}
Imports System
Imports System.Globalization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Navigation

Module ConsoleApp

    Sub Main()
        Using site As New SPSite("https://localhost")
            Using web As SPWeb = site.OpenWeb()

                web.QuickLaunchEnabled = True
                web.IsMultilingual = True

                Dim list As SPList = web.Lists.TryGetList("Announcements")
                If list IsNot Nothing Then
                    ' Create a navigation node pointing to the Announcements list.
                    Dim newNode As New SPNavigationNode(list.Title, list.DefaultViewUrl)

                    ' Add the node to the Quick Launch area.
                    Dim quickLaunch As SPNavigationNodeCollection = web.Navigation.QuickLaunch
                    quickLaunch.AddAsLast(newNode)

                    ' Copy translations of the list's title to the user resource for the node's title.
                    Dim localizedTitle As String
                    For Each culture As CultureInfo In web.SupportedUICultures
                        localizedTitle = list.TitleResource.GetValueForUICulture(culture)
                        newNode.TitleResource.SetValueForUICulture(culture, localizedTitle)
                    Next
                    newNode.Update()
                End If

            End Using
        End Using
        Console.Write(vbCrLf & "Press ENTER to continue....")
        Console.Read()
    End Sub

End Module

See Also

Reference

SPNavigationNode Class

SPNavigationNode Members

Microsoft.SharePoint.Navigation Namespace

Title