Share via


CategoryCollection Class

Represents a collection of Category objects.

Inheritance Hierarchy

System.Object
  Microsoft.Office.Server.Search.Administration.CategoryCollection

Namespace:  Microsoft.Office.Server.Search.Administration
Assembly:  Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class CategoryCollection _
    Implements IEnumerable
'Usage
Dim instance As CategoryCollection
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class CategoryCollection : IEnumerable

Remarks

Use the AllCategories property of the Schema class to get the collection of managed properties in the Shared Service Provider's search schema.

Use an indexer to return a single category from the CategoryCollection object. For example, assuming the collection is assigned to a variable named categories, use categories[index] in Microsoft Visual C# or categories(index) in Microsoft Visual Basic, where index is a string containing the name of the category or a GUID that identifies the property set for a category.

Use the Create() method of the CategoryCollection class to create a new category in the search schema.

Use the Delete method of the Category class to delete a category in the search schema.

Examples

The following code example writes out the full list of categories to the console window.

Prerequisites

Ensure a Shared Service Provider is already created.

Project References

Add the following Project References in your console application code project before running this sample:

  • Microsoft.SharePoint

  • Microsoft.Office.Server

  • Microsoft.Office.Server.Search

using System;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
namespace CategoriesSample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //Replace <SiteName> with the name of a site using the Shared Service Provider.
                string strURL = "http://<SiteName>";
                Schema sspSchema = new Schema(SearchContext.GetContext(new SPSite(strURL)));
                CategoryCollection categories = sspSchema.AllCategories;
                foreach (Category category in categories)
                {
                    Console.WriteLine(category.Name);
                }
            }
            catch(Exception ex)
            {
                 Console.WriteLine(ex.ToString());
            }
        }
    }
}

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

CategoryCollection Members

Microsoft.Office.Server.Search.Administration Namespace