/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; string url = Params["url"].Value.TrimEnd('/'); using (SPSite site = new SPSite(url)) { using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)]) { foreach (SPLanguage lang in web.RegionalSettings.InstalledLanguages) { foreach (SPWebTemplate template in site.GetWebTemplates((uint)lang.LCID)) { output += template.Name + " = " + template.Title + " (" + lang.LCID + ")\r\n"; } foreach (SPWebTemplate template in site.GetCustomWebTemplates((uint)lang.LCID)) { output += template.Name + " = " + template.Title + " (Custom)(" + lang.LCID + ")\r\n"; } } } } return (int)ErrorCodes.NoError; }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; string url = Params["url"].Value.TrimEnd('/'); using (SPSite site = new SPSite(url)) { using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)]) { foreach (SPLanguage lang in web.RegionalSettings.InstalledLanguages) { foreach (SPWebTemplate template in site.GetWebTemplates((uint)lang.LCID)) { output += template.Name + " = " + template.Title + " (" + lang.LCID + ")\r\n"; } foreach (SPWebTemplate template in site.GetCustomWebTemplates((uint)lang.LCID)) { output += template.Name + " = " + template.Title + " (Custom)(" + lang.LCID + ")\r\n"; } } } } return((int)ErrorCodes.NoError); }
private SPWebTemplate GetCustomWebTemplate(string template, SPSite site, SPWeb web) { SPWebTemplateCollection templates; SPWebTemplate webTemplate; // Create a web with custom based template templates = site.GetCustomWebTemplates((uint)web.Locale.LCID); webTemplate = LocateTemplateByName(templates, template); return(webTemplate); }
private SPWebTemplate LookupTemplateIDInGallery(SPSite site, string templateName) { SPWebTemplateCollection templates = site.GetCustomWebTemplates(LCID); foreach (SPWebTemplate template in templates) { if ((template.Name.ToLower() == templateName.ToLower()) || (template.Title.ToLower() == templateName.ToLower())) { return(template); } } return(null); }
/// <summary> /// Gets the web template. /// </summary> /// <param name="site">The site.</param> /// <param name="lcid">The lcid.</param> /// <param name="webTemplateName">Name of the web template.</param> /// <returns></returns> internal static SPWebTemplate GetWebTemplate(SPSite site, uint lcid, string webTemplateName) { SPWebTemplateCollection webTemplates = site.GetWebTemplates(lcid); SPWebTemplateCollection customWebTemplates = site.GetCustomWebTemplates(lcid); SPWebTemplate template = null; try { template = webTemplates[webTemplateName]; } catch (ArgumentException) { try { return(customWebTemplates[webTemplateName]); } catch (ArgumentException) { return(template); } } return(template); }
private List <SPSKeyValuePair> GetAvailableSiteTemplates() { SPWeb web = SPContext.Current.Web; SPSite site = web.Site; SPWebTemplateCollection siteTemplates = site.GetCustomWebTemplates((uint)web.Locale.LCID); var templates = new List <SPSKeyValuePair>(); foreach (SPWebTemplate template in siteTemplates) { templates.Add(new SPSKeyValuePair(template.Title, template.DisplayCategory)); } siteTemplates = site.GetWebTemplates((uint)web.Locale.LCID); foreach (SPWebTemplate template in siteTemplates) { if (!template.IsHidden) { templates.Add(new SPSKeyValuePair(template.Title, template.DisplayCategory)); } } return(templates); }
private SPWeb CreateWeb(string title, string parentUrl, string template) { if (string.IsNullOrEmpty(title)) { throw new ArgumentException("Web title can't be null or empty."); } if (string.IsNullOrEmpty(parentUrl)) { throw new ArgumentException("Web parentUrl can't be null or empty."); } Trace.WriteLine(string.Format("Creating test web {0} at {1}", title, parentUrl)); _site = new SPSite(UrlTestSite + parentUrl); SPWeb web = _site.OpenWeb(); SPWeb newWeb; if (web == null) { throw new Exception(string.Format("CanĀ“t open SharePoint Site at: {0}", _site.Url)); } // If exist delete if (web.Webs[title].Exists) { throw new Exception(string.Format("There is already a web in this url.{0}", web.Webs[title].Url)); //RecursiveDeleteWebs(web.Webs[title]); //web.Webs[title].Delete(); } // Simple STS site if (template.Equals(string.Empty)) { newWeb = web.Webs.Add(title); } else { // Create a web with custom based template try { SPWebTemplateCollection webTemplateCollection; webTemplateCollection = _site.GetCustomWebTemplates((uint)web.Locale.LCID); SPWebTemplate webTemplate = webTemplateCollection[template]; newWeb = web.Webs.Add(title, title, string.Empty, (uint)web.Locale.LCID, webTemplate, true, false); } catch (ArgumentException) // Not a custom template { newWeb = web.Webs.Add(title, title, string.Empty, (uint)web.Locale.LCID, template, true, false); } } Trace.WriteLine(string.Format("Created web {0} at {1}", newWeb.Title, newWeb.Url)); return(newWeb); }
/// <summary> /// Gets the web template. /// </summary> /// <param name="site">The site.</param> /// <param name="lcid">The lcid.</param> /// <param name="webTemplateName">Name of the web template.</param> /// <returns></returns> internal static SPWebTemplate GetWebTemplate(SPSite site, uint lcid, string webTemplateName) { SPWebTemplateCollection webTemplates = site.GetWebTemplates(lcid); SPWebTemplateCollection customWebTemplates = site.GetCustomWebTemplates(lcid); SPWebTemplate template = null; try { template = webTemplates[webTemplateName]; } catch (ArgumentException) { try { return customWebTemplates[webTemplateName]; } catch (ArgumentException) { return template; } } return template; }