SPNavigationNode.TitleResource property
會取得 object,代表可用來取得或設定導覽節點標題翻譯SPUserResource 。
Namespace: Microsoft.SharePoint.Navigation
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public ReadOnly Property TitleResource As SPUserResource
Get
'用途
Dim instance As SPNavigationNode
Dim value As SPUserResource
value = instance.TitleResource
public SPUserResource TitleResource { get; }
Property value
Type: Microsoft.SharePoint.SPUserResource
包含可用來取得或設定導覽節點標題的轉譯使用者資源的物件。
備註
此屬性是Title屬性,會傳回TitleResource.Value所傳回的字串的來源。此運算式所傳回的值可以會根據目前的執行緒CurrentUICulture的值而有所不同。如需詳細資訊,請參閱 < SPUserResource.Value屬性。
Examples
下列範例會為主控台應用程式會建立新的瀏覽節點的宣告清單的連結,並將節點新增至快速啟動] 區域中的網站。然後在應用程式逐一查看網站的多語系使用者介面所支援的語言清單和程式碼會當地語系化的值從宣告清單的TitleResource屬性複製到節點TitleResource屬性。
提示
如果您已部署的資源檔案 (.resx) 轉譯,以支援您的應用程式,然後您不需要設定TitleResource屬性,如範例不會。而是將資源運算式傳遞至SPNavigationNode建構函式。例如,下列程式碼行建構節點宣告清單的連結:
SPNavigationNode newNode = new SPNavigationNode("$Resources:core,announceList", list.DefaultViewUrl);
當做第一個引數傳遞字串中,字元"$"表示運算式、 「 資源 」 表示運算式的類型、"核心"是資源檔的名稱及"announceList"是資源的名稱。不允許空格資源運算式中讓逗號後沒有任何空格。
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