SPUserResource.SetValueForUICulture 方法

设置为指定的区域性的资源的值。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
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
    类型:System.String

    一个字符串,包含指定区域性中的资源的值。

异常

异常 条件
ArgumentNullException

cultureInfo是 null 。

示例

下面的示例是一个控制台应用程序,创建一个新的导航节点链接到通知列表并将节点添加到网站的快速启动区域。应用程序然后循环访问网站的多语言用户界面支持的语言的列表,并调用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 类

SPUserResource 成员

Microsoft.SharePoint 命名空间