How to: Add a file type to Enterprise Search programmatically
Posted
Thursday, April 30, 2009 9:21 AM
by
CoreyRoth
If you’re like me, you like to have as few manual steps in your deployment documentation as possible. It’s easy to use the UI of your SSP to add a file extension to the list. However, I would rather have code put those settings in there for me. That is just one less thing the next person has to worry about when deploying to a new server. The code is quite simple for this.
The first thing you want to do is add a reference to the search administration assembly.
using Microsoft.Office.Server.Search.Administration;
The first thing you need to do is get access to the Content object which lets you configure various things in Enterprise Search. You do this by passing an instance of SearchContext.Current which represents the search service on the current SSP.
Content serverContent = new Content(SearchContext.Current);
Once you have a reference to the Content object, you can use the ExtensionList collection to create the new file type. The Create method takes a string with the file type. In this case, a period is not included in the file extension. That means you would pass png instead of .png.
serverContent.ExtensionList.Create("png");
That is really all that is required. Just two lines of code. The Content object will allow you to make many other changes as well to your search settings, such as content sources, property mappings, crawl rules, etc. You can write code to configure these too, but I still use the SharePoint Shared Services Provider Property Creation tool quite a bit.
Follow me on twitter.