ContentSourceCollection Class
Represents a collection of ContentSource objects.
Inheritance Hierarchy
System.Object
Microsoft.Office.Server.Search.Administration.ContentSourceCollection
Namespace: Microsoft.Office.Server.Search.Administration
Assembly: Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)
Syntax
'Declaration
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public NotInheritable Class ContentSourceCollection _
Implements IEnumerable
'Usage
Dim instance As ContentSourceCollection
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
public sealed class ContentSourceCollection : IEnumerable
Remarks
For more information about content sources and the new SharePoint Enterprise Search Administration object model, see Content Sources Overview, and Getting Started with the Search Administration Object Model.
Use the ContentSources property of the Content class to get the collection of content source for a Shared Services Provider.
To add a new content source to the collection, use the Create() method of the ContentSourceCollection class.
To delete a content source, use the Delete method of the ContentSource class.
Use an indexer to return a single content source from the ContentSourceCollection object. For example, assuming the collection is assigned to a variable named sspContentSources, use sspContentSources[index] in Microsoft Visual C# or sspContentSources(index) in Microsoft Visual Basic, where index is a string containing the name of the content source or an integer containing the content source identifier.
Examples
The following code example writes out the full list of content sources for a Shared Services Provider 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
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
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.