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();
}
}
}
Comments
- Anonymous
June 23, 2008
PingBack from http://wordnew.acne-reveiw.info/?p=2070