Thursday, April 30, 2009

Creating SharePoint Web Application Step By Step


Guys,


This is my first blog in the series of
Step By Step MOSS 2007, so here it goes



Creating SharePoint Web Application Step By Step

Before starting the example, the following are the prerequisiteuisite for implementing this example.


  1. Window Server 2003
  2. Should have functional Microsoft Office SharePoint server 2007,
  3. Microsoft Visual Studio 2005/2008
  4. Microsoft office sharepoint extensions Microsoft Visual Studio 2005/2008 (Optional)

If you have ever got a chance to create the SharePoint WebApplication from the SharePoint 3.0 Central Administration,

you would have be very pleased to create the SharePoin
t WebApplication with no fuss,


but let me assure you that creating WebApplication using Visual Studio is much easier,


Now, the Step Begins

  1. Open Visual Studio.
  2. Click on the File in the top menu bar,
  3. Select Create -> Project
  4. Select ConsoleApplication
  5. Name the Console Application as SMK_CreatingWebApplication
  6. Visual Studio itself create the main method for you
  7. Now Add Reference of Microsoft.Sharepoint.Services(Figure A)
  8. Browse to c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI (Figure B)
  9. Select Microsoft.Sharepoint.dll, then click ok(Figure C)
  10. Once the Add Reference Process Completed get back to program.cs file in Visual Studio
  11. Now add using Microsoft.SharePoint.Administration; using Microsoft.SharePoint; at the top of the file Program.cs File
  12. In the Main Method Create SPWebApplicationBuilder Object
  13. SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);
  14. Call the SPWebApplicationBuilder.Create() method which in return provide the instance of SPWebApplicaiton.
  15. After the SpWebApplication Created it is now time to provision SharePoint WebApplication by SpWebApplication.provision()



Before Finishing off this example, let me get through the difference between SpWebApplicationBuilder and SpWebApplication,

SpWebApplicationBuilder is used to create the SpWebApplicationBuilder.
SpWebApplicationBuilder onces instantiated not only picks out unused port for hosting the SpWebApplication, but also get the default setting for creating the SpWebApplication,
On the Otherhand you can change the default setting for SpWebApplication as your need.




Figure A





Figure B




Figure C











Output




using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;

namespace SMK_CreatingWebApplication
{
class Program
{
static void Main(string[] args)
{
///
///this program is to create the Sharepoint WebApplicaton, the Web application is created by the
/// class SPWebApplicationBuilder, SPWebApplicationBuilder pick out the randomize port
/// and default setting to create Sharepoint WebApplicaton. However you can also create the
/// Sharepoint WebApplication as you wish by changing the setting in SPWebApplicationBuilder
///



SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);

Console.WriteLine("Creating WebApplicaiton");

Console.WriteLine("Computer Name: " + webAppBuilder.DefaultZoneUri.Host);

Console.WriteLine("Port Number: "+ webAppBuilder.Port);

Console.WriteLine("Application PoolID: " + webAppBuilder.ApplicationPoolId);

Console.WriteLine("DataBase Server Name: " + webAppBuilder.DatabaseServer);

Console.WriteLine("DataBase Name: "+webAppBuilder.DatabaseName);


//creating SharePoint WebApplication
SPWebApplication webApp = webAppBuilder.Create();

//provisioning SharePoint WebApplication
webApp.Provision();



}
}
}



Code




What Next -> Creating SharePoint WebSites Step By Step




Cheers,


Happy Coding,


7 comments:

Syed Rehan Wasti said...
This comment has been removed by the author.
Web Classified Ads said...

please can you share the Sharepoint Server Installer

Shakir said...

you can google for finding the installing sharepoint.

or look into this article

http://www.datasprings.com/Resources/ArticlesInformation/OverviewonInstallingSharepoint2007/tabid/774/language/en-US/Default.aspx

Imran Raza said...

Nice blog , keep going, how will i test this work on sharepoint, whether it has created successfully or not...

Shakir said...

Imran, once the program run successfully, you can check the created web application in the IIS

Syed Muhammad Ehsan said...

Thanx for posting this article it realy helped me in understanding site creation

Anonymous said...

Thanks for the sharing point. this templates.
more templates
http://www.itsolusenz.com