Code Sample: MyFileConnector Custom Indexing Connector
Applies to: SharePoint Server 2010
The MyFileConnector Custom Indexing Connector sample demonstrates how to create a basic indexing connector that crawls all files and folders within a file share on a Windows file system. This sample is designed to show you how to create custom indexing connectors. For more information about creating custom indexing connectors, see Creating a Custom Indexing Connector. You can download the code for this sample from the MyFileConnector Custom Indexing Connector Sample resource page.
MyFileConnector Project
The MyFileConnector project defines the following classes:
MyFile Defines the file external content type.
MyFolder Defines the folder external content type.
MyFileProxy Contains the method implementations for the Finder and SpecificFinder operations.
MyFileConnector Derives from the StructuredRepositorySystemUtility<T> class, which implements the ISystemUtility interface.
MyFileLobUri Derives from the LobUri class, which maps the URLs as they are passed from the Search service application to Microsoft Business Connectivity Services (BCS).
MyFileNamingContainer Implements the INamingContainer interface, and maps the URLs as they are passed from Business Connectivity Services to the Search service application.
Installing the MyFileConnector Sample
To install the MyFileConnector sample, you must build the sample assembly, register the assembly in the global assembly cache, and register the custom indexing connector with the Search service application. Then, you must create a content source and configure the crawl for the external data type.
To install the MyFileConnector sample
Download the MyFileConnectorSample compressed (.zip) file, which includes the MyFileConnector Microsoft Visual Studio project and the MyFileModel.xml Business Connectivity Services model file.
Extract the contents to a folder on your computer.
Open the MyFileConnector project in Visual Studio.
In Solution Explorer, expand the References folder, and then restore any missing project references. The sample includes references to the following SharePoint Server 2010 assemblies:
Microsoft.BusinessData
Microsoft.SharePoint
Microsoft.Office.Server.Search.Connector
On the application server, add the sample assembly (MyFileConnector.dll) to the global assembly cache. For more information, see How to: Install an Assembly into the Global Assembly Cache.
Copy MyFileModel.xml to the application server.
Open the SharePoint Management Shell. For information about using this tool, see Administering Service Applications Using the SharePoint 2010 Management Shell.
At the command prompt, do the following:
Type the following command, and then run it.
$searchapp = Get-SPEnterpriseSearchServiceApplication
Type the following command, and then run it.
New-SPEnterpriseSearchCrawlCustomConnector -SearchApplication $searchapp -protocol myfile -ModelFilePath "\\ServerName\FolderName\MyFileModel.xml" -Name myfile
Add the following registry subkey to the server, and then set the value to OSearch14.ConnectorProtocolHandler.1:
[HKEY_LOCAL_MACHINE]\ SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ProtocolHandlers\myfile
At the command prompt, do the following:
Type the following command, and then run it.
net stop osearch14
Type the following command, and then run it.
net start osearch14
On the Search Administration page, click Content Sources, and then click New Content Source.
Specify a name for the content source, and in Content Source Type, click Custom Repository.
In Type of Repository, click myfile.
In Start Addresses, type the following:
myfile://FileServerName/FileShareName/