Using SPFarm in SharePoint
How to use SPFarm
SPFarm is the top level object in
SharePoint for any SharePoint installation involves the Farm configuration this
is the main object through it is possible to identify collection of server
running in the current SharePoint Farm
The sample demo shows how to access the
SPFarm Object using SharePoint Object Model
The following sample demonstrate how we can
iterate through the farm.Servers that is servers
collection
And adding these information in two
dictionaries
Code:
SPFarm farm = SPFarm.Local;
Dictionary<string,
string> serversNames = new Dictionary<string, string>();
Dictionary<string,
string> serversAddress = new Dictionary<string, string>();
int counter = 0;
foreach (SPServer
server in farm.Servers)
{
serversNames.Add("Server Name : "
+ counter, server.Name);
serversAddress.Add("Address of Server:
" + counter, server.Address);
counter++;
}
No comments:
Post a Comment