Thursday, June 27, 2013

How to get Search Service Applications Programmatically

Leave a Comment
Today i came across scenario, where i need to get programmatically list of Service Service Applications in the farm.

Below code snippet will show search service applications in the farm.


using System.Linq;
using Microsoft.SharePoint.Administration;

namespace SearchApplications
{
    internal class Program
    {
        private static void Main(string[] args)
        {
 
                           var farm = SPFarm.Local;
                           var service = farm.Services.OfType<SearchQueryAndSiteSettingsService>().First();
                           var applications = service.Applications.ToList();

                           foreach (var app in applications)
                           {
                                Console.WriteLine(app.Name);
                           }  
        }
    }
}


0 comments: