Friday, July 17, 2009

Understanding SPApplicationPool Class

Hi All,

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:

Jimesh said...

Hi Malay,

Can we get this password value by setting SPSecurity.RunWithElevatedPrivileges?

SharePoint Kings said...

Which password you are referring?




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com