Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CategoryCollection class

Represents a collection of Category objects.

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)
'Declaration
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
PublicNotInheritableClassCategoryCollection _
	ImplementsIEnumerable
'Usage
DiminstanceAsCategoryCollection

Use the AllCategories property of the Schema class to get the collection of managed properties in the Shared Services 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.

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

Prerequisites

Ensure a Shared Services Provider is already created.

Project References

Add the following project references in your console application code project before running this example:

  • Microsoft.SharePoint

  • Microsoft.Office.Server

  • Microsoft.Office.Server.Search

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.Office.Server.Search.Administration
Imports Microsoft.SharePoint
Namespace CategoriesSample
    Module Program
        Sub Main(ByVal args() As String)
            Try
                ' Replace SiteName with the name of a site using the Shared Services Provider.
                Dim strURL As String = "http://<SiteName>"
                Dim sspSchema As New Schema(SearchContext.GetContext(New SPSite(strURL)))
                Dim categories As CategoryCollection = sspSchema.AllCategories
                For Each category As Category In categories
                    Console.WriteLine(category.Name)
                Next category
            Catch ex As Exception
                Console.WriteLine(ex.ToString())
            End Try
        End Sub
    End Module
End Namespace
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.