Sunday, November 16, 2008

SharePoint Site (individual) Provisioning (Code)

in my previous blog for SharePoint Site Provisioning (Code), it is only used when you are creating sites for the first time. Now imagine if you have already and site and you want to add another site to the WebApp individually. You might want to consider the below.


public static string CreateClientSite(SPWebApplication app, string path, int siteId, string title, string owner)
{
string url;

if (string.IsNullOrEmpty(owner) owner == "{current}")
{
IIdentity identity = System.Threading.Thread.CurrentPrincipal.Identity;
WindowsIdentity winIdentity = identity as WindowsIdentity;
owner = winIdentity != null ? winIdentity.Name : clientSiteOwner;
}

using (SPSite site = app.Sites.Add(string.Format(path, siteId),
title, string.Empty, 1033, null, owner,
"Application Admins",
"<EmailID>"))
{
url = SetWebSettings(site, siteId);
}

return url;
}

private static string SetWebSettings(SPSite site, int siteId)
{
string url;
using (SPWeb web = site.RootWeb)
{
web.Properties<:Property>] = <VALUE>;
web.Properties.Update();
web.ApplyWebTemplate(<TemplateId>);

url = web.ServerRelativeUrl;
}
return url;
}

No comments: