Programmatically retrieve a list of the file extensions from the SSP Search Service
I recently had to expose the file extensions that we allow search to index outside of SharePoint. Unfortunately SharePoint does not expose this out of the box. So i had to write a web service to be deployed in MOSS that would expose the file extension list.
Here's the code I used to accomplish this...
FileExtensionService.cs
-------------------------------
using System.Collections.Generic;
using System.Text;
using msa=Microsoft.Office.Server.Search.Administration;
using ma = Microsoft.SharePoint.Administration;
using System.Web.Services;
using System.Web;
namespace Samples.SharePoint.WebServices
{
[WebService]
public class FileExtensionService
{
const string GetFileExtensionsCacheString = "FileExtensionService.GetFileExtensions";
public FileExtensionService()
{
}
[WebMethod(Description="Gets the Extensionlist out of moss")]
public string[] GetFileExtensions()
{
List<string> extensions = HttpContext.Current.Cache[GetFileExtensionsCacheString] as List<string>;
if (extensions == null)
{
extensions = new List<string>();
Microsoft.Office.Server.ServerContext server = Microsoft.Office.Server.ServerContext.Default;
msa.SearchContext context = msa.SearchContext.GetContext(server);
msa.Content ssp = new msa.Content(context);
foreach (msa.Extension extension in ssp.ExtensionList)
{
extensions.Add(extension.FileExtension);
}
HttpContext.Current.Cache[GetFileExtensionsCacheString] = string.Concat(".",extensions);
}
return extensions.ToArray();
}
}
}
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using
I'm a consultant for Microsoft Consulting Services specializing in SharePoint and BI Products. I've been with Microsoft since 03/2006. The opinions expressed herein are my own personal opinions and do not represent my employer's views in anyway.