Thursday, 11 July 2013

Getting list of running services on SharePoint Farm

                   

 Using SharePoint Object Model  to get list of all running services

                Getting what are the services are running in the current SPFarm...........

using System;
using System.Web.UI;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

protected void Page_Load(object sender,EventArgs e)
{
try
            {            
              
                List<string> onLineService = new List<string>();
                List<string> offLineService = new List<string>();
                
               SPFarm farm = SPContext.Current.Site.WebApplication.Farm;             

              // Getting all services in the current Farm
                foreach (SPService service in farm.Services)                   
                {
                   // Getting all  running services using online
                    if (service.Status.Equals(SPObjectStatus.Online))
                    {
                        ListBoxOnLine.Items.Add(service.Name);
                        
                    }
                   // Getting all  running services using offline
                    else if (service.Status.Equals(SPObjectStatus.Offline))
                    {
                        ListBoxOffLine.Add(service.Name);
                    }
                }
            }
            catch (Exception)
            {                
                throw;

            }
}


No comments:

Post a Comment