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


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.


# re: How to: Add a file type to Enterprise Search programmatically

Tuesday, May 18, 2010 2:09 PM by Soumya

Thanks Corey. I was looking to do just this and this was a great help. One quick question though, how do you delete any file type. In the ExtensionCollection, I do not see any delete method. But there must be a way to do that.

# re: How to: Add a file type to Enterprise Search programmatically

Thursday, August 18, 2011 4:19 AM by Suresh

Thx for this neat 3 lines of code. Just what I'm looking for. Im deploying a Farm Feature, which create the file extension by this mentioned way, but the question is. Is there a way to check whether an extension is already created and only create if not already exists. In some situations I also need to delete some extensions, how to do that?

Leave a Comment