Ömer Çelik

Yazılımcının Günlüğü

Site şablonu kullanarak yeni bir site oluşturmak

        public static string getTemplate(string SiteUrl, string WebTemplateName)

        {

            string TemplateName = string.Empty;

            SPSecurity.RunWithElevatedPrivileges(

             delegate

             {

                 using (var site = new SPSite(SiteUrl))

                 {

                     using (var web = site.OpenWeb())

                     {

                         SPWebTemplateCollection templates = web.Site.GetWebTemplates(1055);

                         foreach (SPWebTemplate template in templates)

                         {

                             string[] templateInfo = template.Name.Split('#');

                             string CustomWebTemplateName = templateInfo[1];

                             if (CustomWebTemplateName.ToLower().Equals(WebTemplateName.ToLower()))

                             {

                                 TemplateName = template.Name;

                                 break;

                             }

                         }

                     }

                 }

             });

            return TemplateName;

        }

        public static void CreateSubSite(string siteName, string SiteUrl, string WebTemplateName, string strTitle, string strDescription)

        {

            SPSecurity.RunWithElevatedPrivileges(

                 delegate

                 {

                     using (SPSite newSite = new SPSite(SiteUrl))

                     {

                         newSite.AllowUnsafeUpdates = true;

                         SPWeb newWeb = newSite.OpenWeb();

                         newWeb.AllowUnsafeUpdates = true;

                         SPWebCollection subSites = newWeb.Webs;

                         SPWeb newSubWeb = subSites.Add(siteName, strTitle, strDescription, 1055, WebTemplateName, true, false);

                         newWeb.Update();

                         newWeb.AllowUnsafeUpdates = false;

                         newSite.AllowUnsafeUpdates = false;

                         newSite.Dispose();

                     }

                 });

        }

Loading