Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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*

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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);
                    }
                }
            }
share|improve this answer
    
+1, but I tried it your way and I tried it by going through "SPWebTemplateCollection" but its giving null :S –  Muhammad Raja Aug 3 '12 at 14:33
    
GetWebTemplates method worked for me, ta –  Muhammad Raja Aug 3 '12 at 14:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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