CategoryCollection 类
表示Category对象的集合。
继承层次结构
System.Object
Microsoft.Office.Server.Search.Administration.CategoryCollection
命名空间: Microsoft.Office.Server.Search.Administration
程序集: Microsoft.Office.Server.Search(位于 Microsoft.Office.Server.Search.dll 中)
语法
声明
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public NotInheritable Class CategoryCollection _
Implements IEnumerable
用法
Dim instance As CategoryCollection
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
public sealed class CategoryCollection : IEnumerable
备注
使用Schema类的AllCategories属性以获取共享服务提供程序的搜索架构中的托管属性的集合。
使用索引器返回的CategoryCollection对象从单个类别。例如,假定该集合分配给名为categories的变量,使用categories[index] 在 Microsoft Visual C# 或categories(index) 在 Microsoft Visual Basic,索引是一个字符串,该字符串包含的类别的名称或 GUID 标识的属性设置为某一类别的位置。
使用CategoryCollection类的**Create()**方法在搜索架构中创建一个新类别。
Category类的Delete方法用于删除搜索架构中的一个类别。
示例
下面的代码示例将写出到控制台窗口的类别的完整列表。
Prerequisites
确保已创建了共享服务提供程序。
Project References
运行此示例之前,控制台应用程序的代码项目中添加了以下项目引用:
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 Services 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());
}
}
}
}
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
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。