in

SharePoint University

Clean slate. Nothing but SharePoint.
Go, SharePoint!

Upgrading Site Definition / Site Templates

Last post 07-07-2008 4:24 AM by Druk. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-04-2008 10:13 AM

    • Druk
    • Top 500 Contributor
    • Joined on 11-09-2007

    Upgrading Site Definition / Site Templates

    Hi,

    I have deployed a custom site template in a solution which worked very well.

     
    I have now upgraded the solution to include a second site template. This template is available in the Site Actions >> Create Site section, but is only appearing as an option in sites created after the solution was redeployed (I am controlling what site templates may be selected as sub sites in the onet file with the AvailableWebTemplates property).

    I guess on site creation the template is checked, the site is created and any changes made to the template after the fact are not picked up on by existing sites.

    Is there a way of making the template available to existing sites, so in a way refer back to the new template model, or in some way refresh the AvailableWebTemplates property of existing sites to include the new site template type?

    The template may be added by site owners manually, but I would rather avoid this scenario.

     Many thanks for any and all help!

     
    D
     


     

  • 07-06-2008 9:55 AM In reply to

    • furuknap
    • Top 10 Contributor
    • Joined on 10-05-2007
    • Oslo, Norway

    Re: Upgrading Site Definition / Site Templates

    Hello,

    The AvailableWebTemplates property resides in the propertybag of the site and as with other properties it is not a reference back to the site template but is a copy of what was in the site template when the site was provisioned. As such, the only way to change this setting after the site has been provisioned is to update all sites with the new setting.

    You can set the property just like any other property:

    site.Properties["AvailableWebTemplates"] = <some value>;

    However, the value of AvailableWebTemplates has a semicolon delimited syntax. Basically the format is 'locale-templatename#templatenumber;locale-templatename#templatenumber'. For instance, to add the STS template 1 for English you add

    site.Properties["AvailableWebTemplates"] = "1033-STS#1;";

    To add the template for any locale you just use a * instead of a number, ie '*-STS#1'.

    .b

    http://furuknap.blogspot.com/
    My SharePoint blog with articles, reviews, and code samples. Anonymized questions and answers may be posted to my blog.

    My Business Process Management article series:
    SharePoint Designer Workflows (Part 1 of 3)
    SharePoint Event Receivers (Part 2 of 3)
    Visual Studio Workflows (Part 3 of 3)
  • 07-07-2008 4:24 AM In reply to

    • Druk
    • Top 500 Contributor
    • Joined on 11-09-2007

    Re: Upgrading Site Definition / Site Templates

    Thanks furuknap, that sounds like a good solution.

    As I want to change all the subsites to use the same 2 templates for sub site creation I am looking at using code like:

    SPSite oSiteCollection = new SPSite("http://mycollection");
    SPWebCollection collWebsites = oSiteCollection.AllWebs;


                foreach (SPWeb oWebsite in collWebsites)
                {
                    oWebsite.Properties["AvailableWebTemplates"] = "*-ST1_PUB#0;*-ST2_PUB#1";

                }

    But I am wondering what I should run this under, so far I have developed webparts and controls but I am guessing this could be a little console app?

     
    Thanks,

    D

Page 1 of 1 (3 items)

Need SharePoint Training? Attend a SharePoint Bootcamp!
Forum content (c) original posters. Everything else (c) 2008 SharePoint Experts, Inc.