ContentSourceCollection.Create 方法 (Type, String)
在集合中创建的内容源。
命名空间: Microsoft.Office.Server.Search.Administration
程序集: Microsoft.Office.Server.Search(位于 Microsoft.Office.Server.Search.dll 中)
语法
声明
Public Function Create ( _
type As Type, _
name As String _
) As ContentSource
用法
Dim instance As ContentSourceCollection
Dim type As Type
Dim name As String
Dim returnValue As ContentSource
returnValue = instance.Create(type, name)
public ContentSource Create(
Type type,
string name
)
参数
type
类型:System.Type该内容源的对象类型。
name
类型:System.String一个字符串,它包含的内容源名称。
返回值
类型:Microsoft.Office.Server.Search.Administration.ContentSource
一个ContentSource对象。
备注
有关内容源和新SharePoint 企业级搜索的管理对象模型的详细信息,请参阅Content Sources Overview和入门搜索管理对象模型。
示例
下面的代码示例创建一个自定义内容源。ContentSourceCollection类的**Create()**方法的示例代码的完整、 分步演练,请参见How to: Add a Content Source。
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 AddContentSourceSample
{
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;
// Replace <csName> with the content source name.
CustomContentSource customCS = (CustomContentSource)sspContentSources.Create(typeof(CustomContentSource), "<csName>");
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.Office.Server.Search.Administration
Imports Microsoft.SharePoint
Namespace AddContentSourceSample
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
' Replace <csName> with the content source name.
Dim customCS As CustomContentSource = CType(sspContentSources.Create(GetType(CustomContentSource), "<csName>"), CustomContentSource)
End Sub
End Module
End Namespace