|
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace GeeksConnected.WSSViaCSharp
{
class BuildingWebApplication
{
static void Main(string[] args)
{
//Setting the Web Application and Database Name
string strWebAppName = "Am Created Programmatically";
string strDBName = "WSS_Content_GeeksConnecetedWSSAdminViaCSharp1";
//Getting an instance of the Local Farm
SPFarm spAdminFarm = SPWebService.AdministrationService.Farm;
//Creating an instance of the Web Application Builder
SPWebApplicationBuilder spWebBuilder;
//Creating an instance of the SPWebApplication
SPWebApplication spWebApp;
spWebBuilder = new SPWebApplicationBuilder(spAdminFarm);
//Setting the Port Number of the Web Application
spWebBuilder.Port = 24521;
//Setting the Database Name
spWebBuilder.CreateNewDatabase = true;
spWebBuilder.DatabaseName = strDBName;
//Setting the Security Secttings
spWebBuilder.UseNTLMExclusively = true;
spWebBuilder.AllowAnonymousAccess = false;
spWebBuilder.UseSecureSocketsLayer = false;
//Setting the Application Pool Configuration
spWebBuilder.ApplicationPoolId = strWebAppName;
spWebBuilder.IdentityType = IdentityType.NetworkService;
//Creating the Web Application
spWebApp = spWebBuilder.Create();
//Setting the Web Application Name
spWebApp.Name = strWebAppName;
//Updating the Web Application Information and then provisioning it
spWebApp.Update();
spWebApp.Provision();
//Updating the Appliction Pool Configuration
spWebApp.ApplicationPool.Name = "Programmable Web Pool";
spWebApp.ApplicationPool.Update();
spWebApp.ApplicationPool.Provision();
//Adding the newly created web application to the
//List 'Web Applications List' in Central Administation
SPWebService.AdministrationService.WebApplications.Add(spWebApp);
//After this do iisreset /noforce
}
}
} |