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

  1. Download the MyFileConnectorSample compressed (.zip) file, which includes the MyFileConnector Microsoft Visual Studio project and the MyFileModel.xml Business Connectivity Services model file.

  2. Extract the contents to a folder on your computer.

  3. Open the MyFileConnector project in Visual Studio.

  4. 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

  5. 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.

  6. Copy MyFileModel.xml to the application server.

  7. Open the SharePoint Management Shell. For information about using this tool, see Administering Service Applications Using the SharePoint 2010 Management Shell.

  8. At the command prompt, do the following:

    1. Type the following command, and then run it.

      $searchapp = Get-SPEnterpriseSearchServiceApplication
      
    2. Type the following command, and then run it.

      New-SPEnterpriseSearchCrawlCustomConnector -SearchApplication $searchapp -protocol myfile -ModelFilePath "\\ServerName\FolderName\MyFileModel.xml" -Name myfile
      
  9. 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

  10. 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
    
  11. On the Search Administration page, click Content Sources, and then click New Content Source.

  12. Specify a name for the content source, and in Content Source Type, click Custom Repository.

  13. In Type of Repository, click myfile.

  14. In Start Addresses, type the following:

    myfile://FileServerName/FileShareName/

See Also

Concepts

Creating a Custom Indexing Connector