Create web in Application Page In SharePoint 2010 with VS2010

In this blog, I am creating a one application page, In which I took a one button which create a new web with simple coding in sharepoint portal. I have made my code very simple and easy, though my blog make my life more easier because i dont need to google around for sp code. In this blog I am creating a new site to site colltion will all comments which migh help full in your coding.

(1) Create Empty SharePoint project, make it as farm base solution.

(2) Add Application page on the project.Now you will have the code behind code of page like in

SPWeb thisweb = SPContext.Current.Web;
SPWeb newweb = null;
protected void Page_Load(object sender, EventArgs e)

//creating button event so that we will creaet a single web in it.
creator.Click += new EventHandler(creator_Click);

void creator_Click(object sender, EventArgs e)
#region Add WEbsite
if (!thisweb.Webs[“JobData”].Exists)

//I am creating a blank site, and here 1033 is the Template descrition.
//for more detail about the Shareponit Templates and their respctive description go to Link

newweb = thisweb.Webs.Add(“JobData”, “WebTitle”, “Descrioptioin”, 1033, “STS#1″, true, false);
//Now assigning the Role for user or a gruoup
SPRoleAssignment rollAssign = new
SPRoleAssignment(@”aziz\Administrator”, “”, “Administrator”, “Noted Abdul Aziz”);
//Defining a single role defition of a user to the web.
SPRoleDefinition roleDef = Web.RoleDefinitions[“Contribute”];
//update the database the changes that has been made.
status.Text = “Job Data site and Job data Definition list has been made.”;
creator.Enabled = false;
catch (Exception ex)
status.Text = ex.Message.ToString();

#region CreatingList
//Now deploy the solution and go the followiong url. on sp.


One thought on “Create web in Application Page In SharePoint 2010 with VS2010

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s