ContentSourceCollection 类
表示ContentSource对象的集合。
继承层次结构
System.Object
Microsoft.Office.Server.Search.Administration.ContentSourceCollection
命名空间: Microsoft.Office.Server.Search.Administration
程序集: Microsoft.Office.Server.Search(位于 Microsoft.Office.Server.Search.dll 中)
语法
声明
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public NotInheritable Class ContentSourceCollection _
Implements IEnumerable
用法
Dim instance As ContentSourceCollection
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
public sealed class ContentSourceCollection : IEnumerable
备注
有关内容源和新SharePoint 企业级搜索的管理对象模型的详细信息,请参阅Content Sources Overview,并开始搜索管理对象模型使用。
Content类的ContentSources属性用于获取内容源的共享服务提供程序的集合。
若要向集合中添加新的内容源,请使用ContentSourceCollection类的**Create()**方法。
要删除的内容源,请使用ContentSource类的Delete方法。
使用索引器返回的ContentSourceCollection对象从单个内容源。例如,假定该集合分配给名为sspContentSources的变量,使用sspContentSources[index] 在 Microsoft Visual C# 或sspContentSources(index) 在 Microsoft Visual Basic 中,其中, index是包含该内容源的名称的字符串或一个包含该内容源标识符的整数。
示例
下面的代码示例写出完整的内容源列表中,为共享服务提供程序扩展到控制台窗口。
Prerequisites
确保已创建了共享服务提供程序。
Project References
运行此示例之前,控制台应用程序的代码项目中添加了以下项目引用:
Microsoft.SharePoint
Microsoft.Office.Server
Microsoft.Office.Server.Search
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
namespace ContentSourceSample
{
class Program
{
static void Main(string[] args)
{
/*
Replace SiteName with the name of a site
using the Shared Services Provider.
*/
string strURL = "http://<SiteName>";
SearchContext context;
using(SPSite site = new SPSite(strURL))
{
context = SearchContext.GetContext(site);
}
Content sspContent = new Content(context); ContentSourceCollection sspContentSources = sspContent.ContentSources;
foreach (ContentSource cs in sspContentSources)
{
Console.WriteLine("NAME: " + cs.Name + " ID: " + cs.Id);
}
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.Office.Server.Search.Administration
Imports Microsoft.SharePoint
Namespace ContentSourceSample
Module Program
Sub Main(ByVal args() As String)
'
' Replace SiteName with the name of a site
' using the Shared Services Provider.
'
Dim strURL As String = "http://<SiteName>"
Dim context As SearchContext
Using site As New SPSite(strURL)
context = SearchContext.GetContext(site)
End Using
Dim sspContent As New Content(context)
Dim sspContentSources As ContentSourceCollection = sspContent.ContentSources
For Each cs As ContentSource In sspContentSources
Console.WriteLine("NAME: " & cs.Name & " ID: " & cs.Id)
Next cs
End Sub
End Module
End Namespace
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。