Thursday, February 19, 2009

Create SharePoint Sub Sites

Hi,

Having the last days a conversation with IT director about creating multiple sub-sites, today have some time and make a litle search about creating Sub-Site.
Traveling half Portugal "Lisbon-Porto" in a train, read a litle SharePoint SDK and in fast way find a simple code to create multiple sub-site, using personal templates and user permissions.

Problem:
How do i get The Personal Template?

Go to C:\Program Files\Common Files\Microsoft Shared\Web server extensions\12\Template\[Culture]\xml
and you will see a "WEBTEMPSPS.xml" or other file start with "WEBTEMP*".
Open File and you will see:
Template ID = 20
Name: SPS#0

The Name is the value use to Custom Template




using (SPSite site = new SPSite("[URL Top-Site]"))
{
SPWebApplication webapp= site.WebApplication;
webapp.Sites.Add([Site Path]"/Finance",
[Title]"Finance",
[Sub Site Descrition]"Finance Sub site",
[Language Site]1033,
[Name template]"[SPS#0]",
@"[Domain]\[Login Name]",
[OwnerName]"Administrator",
[Email]);
}

With this example my recomendation to create multiple sites is using XML configuration file to define hierarquical sites and Values ["URL","Title", "Descrition","Template","LoginName","OwnerName",Email].

Using STSADM
Delete Site
c:\programs\....\bin\stsadm -o deletesite -url http://localHost

Build Site
c:\programs\....\bin\stsadm -o createsite -url http://localHost -ownerlogin [Login User] -owneremail [email] -sitetemplate STS#0

Delete a Web Based on a Template
stsadm -o deleteweb -url http://localHost/teste

Create Web Based on a Template
stsadm -o createweb -url http://localhost/teste -lcid 1033 -sitetemplate Helpdesk#1 -title TestWeb


Hope this help creating sub Sites in a fast Way :)
Post a Comment