Wednesday, October 27, 2010

Provision a Site through Programmatically C#

How to Create a Sharepoint Site Programmatically using C#:

(or) Provisioning a Site using C#:

We can add a Site in a Site Collection by using the Method Add in the Class AllWebs.

For Example, If I want to add the Search Center with a site collection,

using (SPWeb newSite = currentWeb.Site.AllWebs.Add("Search", DisplayName,"Renault Search Center", currentWeb.Language, "SRCHCEN#0", false, false))

{

newSite.Navigation.UseShared = true;

PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(newSite);

pWeb.InheritCurrentNavigation = true;

pWeb.NavigationShowSiblings = false;

pWeb.IncludePagesInNavigation = false;

pWeb.IncludeSubSitesInNavigation = false;

pWeb.Update();

newSite.Update();

}

No comments: