We all know that the Web Application is the main container for all site collections. Ultimately it is the whole and sole of all sites created later on.
So in this article, we will learn how to create Web Application programmatically with SPWebApplicationBuilder Class. When we instantiate the object of SPWebApplicationBuilder class, it automatically provides the default values for the required settings.
However there are many other properties that you can set. These are the same properties that we set from UI in central administration at the time of creating web application.
Here is a list of some properties. You can find all properties from of course MSDN.
ApplicationPoolId. – GUID of the application pool that will get created for web application.
ApplicationPoolUsername. – User name of the windows account under whom web application will run.
ApplicationPoolPassword- Password of the windows account under whom web application will run.
CreateNewDatabase. – Gets or sets the Boolean value indicating to create the database for web application or not.
DatabaseName – Name of the database
Port – Port number on which web application runs
Here is a way we will proceed to create web application. First instantiate the SPWebApplicationBuilder class object.
Then you can set different properties. Here I am setting only port number.
Then get the SPWebApplication class object by calling the create method on SPWebApplicationBuilder object.
Here is a short code.
SPWebApplicationBuilder objWebAppBuild= new SPWebApplicationBuilder(SPFarm.Local);
objWebAppBuild.Port = 8880;
SPWebApplication objWebApp= objWebAppBuild.Create();
objWebApp.Provision();
Just to check one important thing is under which account code is running.
That’s it. Your job is done.
1 comment:
how to set the url for this webapplication
Post a Comment