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 asp.net.
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
//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”, “firstname.lastname@example.org”, “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();
//Now deploy the solution and go the followiong url. on sp.