Creating SharePoint Web Sites Step By Step

This is my second blog for the series Step By Step MOSS 2007

In this Blog i elaborate how to create SharePoint WebSites using Visual Studio 2005 or Visual Studio 2008,

here it goes,

Creating SharePoint WebSites Step By Step

Before starting the example, the following are the prerequisite 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)

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_CreatingSites
  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 the SPSite Object, provide the URL of share point webapplicaion on which you want to create the site collection
  13. SPSite site = new SPSite(“URL”);
  14. Create the SpWebApplicton object withrespect to site
  15. SPWebApplication webApp = site.WebApplication;
  16. Add SiteCollection to the above webapplicaton object
  17. webApp.Sites.Add(“SiteUrl”,”Site Title”,”Site Descrition”,“Language ID”,“Template ID”,”User Login”,”Username”,”UserEmailAddress”);
  18. Finally the site created (Figure D,E)

Before Ending this Example, here is the quick notes ,

Language ID (Bold Font), shows the locale on which the site is created, the locale for english is 1033, for finsid is 1035,

In the Template ID, you have to give the ID of the Template, you wish to create, Template have the default feature so that when you create the site it got those features, Figure F show the Template ID and Description

Figure A



Figure B





Figure C



Figure D



Figure E

Figure G

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint.Administration;

using Microsoft.SharePoint;

namespace SMK_CreatingSites

{

class Program

{

static void Main(string[] args)

{

///



/// This Example to Create SharePoint WebSite, the prerequisite of running

/// this example is to have a functional sharepoint web applicaiton in your IIS,

///

///

// SPSite represents the site collection on virtual server, provide the URL of share point webapplicaion

//On which you want to create the site collection

SPSite site = new SPSite(“http://shakirmoss:14320/sites/FirstSiteCollection/”);



// Create the SpWebApplicton object withrespect to site

SPWebApplication webApp = site.WebApplication;

//Add SiteCollection to the above webapplicaton object



//webApp.Sites.Add(“SiteUrl”,

webApp.Sites.Add(“/sites/DesicionMeetings”,



// “Site Title”,

“ImpactProximity Decision Meeting Site”,



//”Site Descrition”,

“Decision Meeting Workspace”,



//”Language ID”,

1033,



//”Template Name”

“MPS#2”,



//”User Login”

@”shakirmoss\Administrator”,

//”Username”

“Administrator”,

//”UserEmailAddress”

“s.majeed@ovrlod.com”);

Console.WriteLine(“ImpactProximity Decision Meeting Site created.”);

Console.ReadLine();

}

}

}

Code

Cheers,

Happy Coding,

Advertisements

About Shakir Majeed

I am SharePoint certified Specialist, SharePoint Trainer, Techie Speaker. I am in-list of Speakers on SharePoint from Microsoft Innovation Center Karachi Pakistan. I am User Group Leader of SharePoint Techies User Group(STUG), View all posts by Shakir Majeed

9 responses to “Creating SharePoint Web Sites Step By Step

  • Naveed Khan

    Nice. Keep it up. :)Naveed

  • Anonymous

    Hi, great post… but i hope that you can give me a hand, because i have an small problem… when I create the webapp everything is ok, but when i try to add a new site collection in the:oSPSite = new SPSite(sUrl)It says that the address doesn't exist, but i can check in Sharepoint and there is…Can you help me please???Nelson

  • Shakir

    create site collection and web application in one run, means that web application has no default page so that you can any web application created, though it does showing in the IIS, but create the Web application and site collection in one program, if u feel any problem still, please leave a comment here

  • Anonymous

    Thank you Shakir,As i told you before I create a webapp, and I can add new sites manually to it but, in my application when i set the Url of the webapp i got an error, that says that my webapp doesn't exist, do you know how could i fix this problem???I have this: SPSite oSPSite = new SPSite(sUrl); SPWeb osPWeb = oSPSite.OpenWeb(); using (SPSite oSiteCollection = new SPSite(sUrl)) { SPWebCollection collWebsites = oSiteCollection.AllWebs; uint ValPage = 1033; try { SPWeb oWebsite = collWebsites.Add(sNewSite, sTitle, sDesc, ValPage, sTemplate, false, false); oWebsite.Dispose();Any idea???

  • Anonymous

    Good Afternoon!!! shakykhan.blogspot.com is one of the best innovative websites of its kind. I enjoy reading it every day. All the best.

  • Anonymous

    This comment has been removed by a blog administrator.

  • Anonymous

    This comment has been removed by a blog administrator.

  • Anonymous

    This comment has been removed by a blog administrator.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: