SPWebApplication webApp = SPContext.Current.Site.WebApplication;
using (SPSite site = webApp.Sites.Add("/sites/site3", "SharePoint", null, 1033, null, "administrator", "Administrator", "admin@admin.com"))
{
SPWeb rootWeb = site.RootWeb;
SPWebTemplateCollection webTemplates = site.RootWeb.GetAvailableWebTemplates(1033);
SPWebTemplate webTemplate = (from SPWebTemplate t
in webTemplates
where t.Title.Equals("NameOfTemplate")
select t).FirstOrDefault();
if (webTemplate != null)
{
site.RootWeb.ApplyWebTemplate(webTemplate.Name);
}
}
ApplyWebTemplate() is raising an SPException. The only further details (including from the InnerException property) I have is that it says:
"Cannot complete this action. Please try again. 0x80004005" with the stacktrace clearly leading me back to ApplyWebTemplate().
This template that I'm applying did call on a custom content type/page layout I had - so I removed all that to ensure that there were no 'missing file' issues.
Can anybody shed any light on where this exception could be coming from?
Thanks a lot.