Export (0) Print
Expand All

SPUserResourceCollection class

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

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

public sealed class SPUserResourceCollection : SPBaseCollection

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.

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("http://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();
        }
    }
}

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