About Me

My photo
a Dynamic and Energetic guy.....

Wednesday, September 17, 2008

Create a SHAREPOINT site collection & subsites programatically

try
{
SPWebApplication webApplication = SPWebApplication.Lookup(new Uri("http://dev3:10131"));
SPSiteCollection siteCollections = webApplication.Sites;
siteCollections.Add("http://dev3:10131/IntranetMOSS", "chanaka_temp", "chanacse@gmail.com");
}
catch(Exception ex)
{
// log the error
}

// Add subsites into the siteCollection
try
{
using (SPSite mySite = new SPSite("http://dev3:10131/IntranetMOSS"))
{
using (SPWeb myWeb = mySite.OpenWeb())
{ //path name
SPWeb newWeb = myWeb.Webs.Add("SBU", "SBU's", "Add for commercial purpose", 1033, "STS#1", false, false);
newWeb.Update();
newWeb = myWeb.Webs.Add("Newss", "News", "Update with the ", 1033, "STS#1", false, false);
newWeb.Update();
newWeb = myWeb.Webs.Add("Groups", "Groups", "As a unit", 1033, "STS#1", false, false);
newWeb.Update();
newWeb = myWeb.Webs.Add("CorporateNews", "Corporate News", "All you need", 1033, "STS#0", false, false);
newWeb.Update();
newWeb = myWeb.Webs.Add("Services", "Services", "Always with you", 1033, "STS#0", false, false);
newWeb.Update();
newWeb = myWeb.Webs.Add("UserManuals", "User Manuals", "Help", 1033, "STS#0", false, false);
newWeb.Update();
}
}
}

// you can set the breadcrumb of the each site through the code also
// Simple task.........


try
{
SPSite ChildSite = new SPSite(web.Url);
SPWeb DChildWeb = ChildSite.OpenWeb();
SPNavigationNode ParentNode = new SPNavigationNode(parentWeb.Title, parentWeb.Url + "/HomePage.aspx", true);
SPNavigationNode ChildNode = new SPNavigationNode(DChildWeb.Title, DChildWeb.Title + "/HomePage.aspx");
parentWeb.Navigation.TopNavigationBar.AddAsLast(ChildNode);
web.Navigation.TopNavigationBar.AddAsFirst(ParentNode);
web.Navigation.UseShared = true;
web.Update();
}
catch (Exception ex)
{
// log this error
}

No comments:

My Masters