I came across to an interesting thing yesterday when I was exploring the various classes of SharePoint. I found a class named SPApplicationPool and immediately I got an idea that we should be able to get this class object by calling ApplicationPool property of SPWebApplication object and I was right.
So let me explain you one more interesting part of this class. It exposes several properties like Username, Name, DisplayName, Propoerties as hash table and most surprisingly password. Yes Password property was there, I thought it must be only having set attribute. But I was very much surprised to see it was gettable. Well I thought for a moment.
Below is just a test code that I ran from console application.
private void button1_Click(object sender, EventArgs e)
{
SPWebApplicationCollection objAllWebApps =
SPWebService.ContentService.WebApplications;
SPApplicationPool objPool = null;
string strApplicationPoolUserName = string.Empty;
string strApplicationPoolPassword = string.Empty;
string strApplicationPoolName = string.Empty;
string strApplicationPoolDisplayName = string.Empty;
string strPropertyKey = string.Empty;
string strPropoertyValue = string.Empty;
Hashtable objHash = new Hashtable();
foreach (SPWebApplication objwebapp in objAllWebApps)
{
objPool = objwebapp.ApplicationPool;
strApplicationPoolUserName = objPool.Username;
strApplicationPoolPassword = objPool.Password;
strApplicationPoolName =objPool.Name;
strApplicationPoolDisplayName = objPool.DisplayName;
objHash = objPool.Properties;
foreach (DictionaryEntry objEntry in objHash)
{
strPropertyKey = objEntry.Key.ToString();
strPropoertyValue = objEntry.Value.ToString();
}
}
}
But then I got to know that you must be an Administrator user to even run this code because ultimately it is all about Microsoft.SharePoint.Administration class.
Apart from this I came across certain properties that may be useful in some scenario. So let me discuss certain properties of SPWebApplication class.
AlertsEnabled (Bool)- Whether you can set the alerts or not.
AlertsMaximum (int) –Gets or sets maximum number of alerts a user can create on list or list item
CanSelectForBackup(Bool) – Indicating whether web application can be backed up or not.
CanSelectForRestore(Bool) – Indicating whether web application can be restored or not.
EventHandlersEnabled – Event Handles are enabled on this web application or not
JobDefinitions – returns all job definitions for the web application
There are many other properties for this class, just explore and check them.
2 comments:
Hi Malay,
Can we get this password value by setting SPSecurity.RunWithElevatedPrivileges?
Which password you are referring?
Post a Comment