0

I have like tens of custom Site definitions, so when I try to create a new site collection I select a template name, let say "ABCD 2020 DEVELOPMENT ISSUE SOLVED" and create a new site based on this template.

when I try to get Template name of same site I just created I get something like this "STSabcsdsjhsd" , i tried following code to get it.

    public void GetSiteTemplate(string siteUrl)
    {
        using (SPSite site = new SPSite(siteUrl))
        using (SPWeb web = site.OpenWeb())
        {
            textBox3.Text = web.WebTemplate.ToString(); // output = "STSxcvmcxv2020"
            textBox4.Text = web.WebTemplateId.ToString(); // output = "100016"
            textBox2.Text = web.Configuration.ToString(); // output = "3"
        }
    }

Now I can't figure out how can I find out the Template Name that I used to create this site at first place, Programmatically

Edit

How can I find Title of a Configuration using its Configuration saved in WEBTEMP*.xml file unless there is a better way to get it*

1 Answer 1

2

I'm sure there's even a more elegant way than this, but this should work:

string siteUrl = "http://yoursiteurl";
            using (SPSite site = new SPSite(siteUrl))
            using (SPWeb web = site.OpenWeb())
            {
                foreach (SPWebTemplate template in site.GetCustomWebTemplates(uint.Parse("1033")))// or GetWebTemplates
                {
                    if (template.ID == web.WebTemplateId || template.Name == web.WebTemplate)
                    {
                        Console.WriteLine("Template in use " + template.Title);
                    }
                }
            }
2
  • +1, but I tried it your way and I tried it by going through "SPWebTemplateCollection" but its giving null :S Aug 3, 2012 at 14:33
  • GetWebTemplates method worked for me, ta Aug 3, 2012 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.