다음을 통해 공유


SPUserResourceCollection class

Represents a collection of user-defined localizable resources associated with a list or a Web site.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.SPUserResourceCollection

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

Syntax

'Declaration
Public NotInheritable Class SPUserResourceCollection _
    Inherits SPBaseCollection
'Usage
Dim instance As SPUserResourceCollection
public sealed class SPUserResourceCollection : SPBaseCollection

Remarks

An object of this type is returned by the SPList.UserResources property and by the SPWeb.UserResources property. The collection contains SPUserResource objects that represent localizable user-defined resources such as the title of a list, the title of a column, the description of a Web site, the display name of a content type.

Examples

The following example is a console application that prints the names and values of user-defined resources in two collections. The first collection consists of resources associated with a Web site, and the second collection consists of resources for a list in the site. Note that the resource values that are printed are the values for the language of the current thread. Values for other languages may exist. For more information, see the SPUserResource class.

using System;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    PrintValues(web.Title, web.UserResources);

                    SPList list = web.Lists.TryGetList("My Custom List");
                    if (list != null)
                        PrintValues(list.Title, list.UserResources);
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.Read();
        }

        static void PrintValues(string parent, SPUserResourceCollection resources)
        {
            Console.WriteLine("Resources for {0}\n", parent);

            string formatString = "{0,-45} {1}";
            Console.WriteLine(formatString, "Name", "Value");

            foreach (SPUserResource resource in resources)
            {
                Console.WriteLine(formatString, resource.Name, resource.Value);
            }

            Console.WriteLine();
        }
    }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

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

                PrintValues(web.Title, web.UserResources)

                Dim list As SPList = web.Lists.TryGetList("My Custom List")
                If list IsNot Nothing Then
                    PrintValues(list.Title, list.UserResources)
                End If

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

    Sub PrintValues(ByVal parent As String, ByVal resources As SPUserResourceCollection)

        Console.WriteLine("Resources for {0}" & vbLf, parent)

        Dim formatString As String = "{0,-45} {1}"
        Console.WriteLine(formatString, "Name", "Value")

        For Each resource As SPUserResource In resources
            Console.WriteLine(formatString, resource.Name, resource.Value)
        Next

        Console.WriteLine()
    End Sub

End Module

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also

Reference

SPUserResourceCollection members

Microsoft.SharePoint namespace

SPList.UserResources

SPWeb.UserResources

Other resources

Multilingual User Interface (MUI)