Sunday, July 30, 2006

Adding a 'Save site as template' Link to Site Settings in WSS v3/MOSS 2007 using a CustomAction Feature


In an earlier post, Shane Young mentioned that the "Save site as template" link is only available under the Look and Feel menu of Site Settings at the Top Level of the site collection in WSS v3/MOSS 2007 Beta 2.  For all subsites, Shane advises to append “_layouts/savetmpl.aspx” to the URL in order to get to the Save Site as Template page.

Shane surmises that the missing link will be corrected by Microsoft post Beta 2, but in the meantime this omission poses a basic opportunity for developers to work with the new Features framework of WSS v3.  A new custom feature could enable site administrators to add a ‘Save site as template’ link to the Site Settings page of any WSS v3 site.

The SaveSiteAsTemplate feature will consist of a Feature.xml and an Elements.xml file.  Feature.xml declares the Feature itself, and Elements.xml further defines the CustomAction for the Look and Feel menu on a Site Settings page.   To get started, create a folder named SaveSiteAsTemplate below the Features folder located at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES on your WSS v3 server.  Create Feature.xml and Elements.xml from the code below and place each file in the SaveSiteAsTemplate folder you just created.

Feature.xml

<?xml version="1.0" encoding="utf-8" ?>

<Feature Id="DE98E72D-80FF-4031-88B0-2E4DEF6312C8"

       Title="Save Site As Template"

       Description="Adds a 'Save Site As Template' link to the Look and Feel menu in Site Settings."

       Version="1.0.0.0"

       Scope="Web"

       Hidden="FALSE"

       xmlns="http://schemas.microsoft.com/sharepoint/" >

       <ElementManifests>

               <ElementManifest Location="Elements.xml" />

       </ElementManifests>

</Feature>

Note the Scope attribute in the Feature element of Feature.xml.  Scope can be set to either Farm, WebApplication, Site or Web.  Also notice that the ElementManifest element points to Elements.xml.

Elements.xml

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

       <CustomAction

       Id="SPSolutions.SaveSiteAsTemplate"

       GroupId="Customization"

       Location="Microsoft.SharePoint.SiteSettings"

       Sequence="1000"

       Title="Save site as template">

               <UrlAction Url="_layouts/savetmpl.aspx"/>

       </CustomAction>

</Elements>

Setting the Location of the CustomAction to Microsoft.SharePoint.Settings and the GroupId to Customization is what decides where the link will be render in the UI. 

Next, install the feature into WSS v3 by using the stsadm tool.  Stsadm.exe is located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN on your WSS v3 server.

stsadm -o installfeature -name SaveSiteAsTemplate

Finally, activate the new feature on your WSS Site by going to Site Settings > Site Features and clicking the Activate button for the new Save Site As Template feature. 

Activate

You should now see a “Save site as template” link under the Look and Feel menu of the Site Settings page.

 

New Link added by Feature

Categories: , , , , ,

5 comments:

Anonymous said...

Hi,
Most of the documents and articles I have read related to custom feature development, the feature is added to location "Microsoft.Sharepoint.SiteSettings".
I want to know, what all other locations are?
What we have to specify in GroupID & Location Attributes?

Thanks in Advance.
Sachin Dekate

Anonymous said...

i am using the site directory template and i have done of the customization. when i got to site setting and search for the save site as template it was not avaiable, but when i have the url as SiteURl/_layouts/savetmpl.aspx, i am able to same the site as a template with out enableing the custom feature.

can any one explain me how this can happen??

Anonymous said...

thanks for this post! I've fighted with this feat all th emorning. Can someone explain me why if Office Pubblishing Feaure is activated the Save Site as template link disappear?

Paul T said...

i've followed the instructions and the operation completed successfully in cmd, yet i can't see the feature anywhere in my farm. it's not listed in the solution management page nor in the farm features, and is not available at any site level. any ideas (i've run an iis reset and also the command execadmsvcjobs, still nothing).

Anonymous said...

Great Article. Thanks!