Hello All,
In a following Post we will see how to create Subsite from the Custom Site Template Programmatically.
In our Example "TemplateName" is our Custom Template.
//if the web is not exists
In a following Post we will see how to create Subsite from the Custom Site Template Programmatically.
In our Example "TemplateName" is our Custom Template.
SPWeb newWeb = null;
try
{
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url, SPContext.Current.Site.SystemAccount.UserToken))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
uint webLcid = oWeb.Language;
//gets the available template and
//check with the our template name and breaks
//check with the our template name and breaks
SPWebTemplate
webTemplate = oWeb.GetAvailableWebTemplates((uint)1033).Cast<SPWebTemplate> ().FirstOrDefault(wt
=>Title.Equals("TemplateName"));
//if the web is not exists
if (!oWeb.Webs[_webURL].Exists)
{
if (webTemplate != null)
{
newWeb =
oSite.AllWebs.Add(obj.WebURL,
obj.WebTitle,
obj.WebDescription,
webLcid,
obj.WebTitle,
obj.WebDescription,
webLcid,
webTemplate,
true, false);
true, false);
newWeb.Update();
}
}
}
}
}
catch (Exception ex)
{
throw;
}
NOTE:In above example WebURL ,WebTitle and WebDescription are reading from the Object which is used a Parameter in Method
0 comments:
Post a Comment