共用方式為


SPUserResource.SetValueForUICulture method

設定指定的文化特性之資源的值。

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

Syntax

'宣告
Public Sub SetValueForUICulture ( _
    cultureInfo As CultureInfo, _
    value As String _
)
'用途
Dim instance As SPUserResource
Dim cultureInfo As CultureInfo
Dim value As String

instance.SetValueForUICulture(cultureInfo, _
    value)
public void SetValueForUICulture(
    CultureInfo cultureInfo,
    string value
)

參數

  • value
    Type: System.String

    字串,包含在指定的文化特性之資源的值。

Exceptions

Exception Condition
ArgumentNullException

cultureInfo是 null 。

Examples

下列範例會為主控台應用程式會建立新的瀏覽節點的宣告清單的連結,並將節點新增至快速啟動] 區域中的網站。應用程式再逐一查看網站的多語系使用者介面所支援的語言清單,並呼叫SetValueForUICulture寫入當地語系化的值從宣告清單的TitleResource屬性的節點TitleResource屬性。

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;
                        SPUserResource titleResource = newNode.TitleResource;
                        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
                    Dim titleResource As SPUserResource = newNode.TitleResource
                    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

請參閱

參照

SPUserResource class

SPUserResource members

Microsoft.SharePoint namespace