By using SharePoint object model we can retrieve the User
Profile Service information like User Profiles and user group details from
UserProfileManager class. Some times we can see “UserProfileApplicationNotAvailable”
error. We can check service availability details using following code block.
public bool IsCurrentServiceisInStart(string serviceName)
{
bool currentServiceisInStart = false;
SPService currentService =
SPFarm.Local.Services.FirstOrDefault(s => s.TypeName.Equals(serviceName));
if (currentService!= null )
{
SPServiceInstance serviceInstance
= service.Instances.FirstOrDefault(i => i.Status == SPObjectStatus.Online);
If(serviceInstance !=null)
currentServiceisInStart=true;
}
return currentServiceisInStart;
}
We can check the current service from SharePoint local
services by mentioning the service application details as “SPFarm.Local.Services.FirstOrDefault”
command in Linq.
We can use this code block while calling SharePoint service
application. Hope this will help.