Who am Anders Rask SharePoint Solution Architect, ProActive A/S Community moderator on sharepoint.stackexchange.com
Developing Custom Web Templates In Visual Studio 2010 #spsuk30
Web Templates? Web Templates is a new site provisioning method in SharePoint 2010 that, amongst other things, can be used with MSOL since it can be deployed as a Sandboxed Solution Relatively unknown, probably due to little attention from product group Should be used when ever possible for branding SharePoint 2010!
Site Templates Site Definitions Feature Stapling Provisioning Providers WebProvisioned event Web Templates Template Provisioning methods
Site Templates A ”light” version of Web Templates. (Most) sites can be saved as template In SP2010 they are WSP solutions (not STP files) Can be imported into Visual Studio to become ”real” Web Templates
Custom Site Definitions Defacto way of customizing SharePoint in SP2007 Many opinions on how (and if) to use them Best Practice to keep site def’s slim (get ID and use feature stapling) That means no modules in ONET.XML and as few features as possible
Feature Stapling Makes it possible to associate (staple) functionality to existing site definitions when site is being provisioned " TemplateName="BLANKINTERNET#0" /> Can also have feature properties Scope is usually Farm, but can also be WebApp or Site To associate to all templates (except Blank) use Global
Provisioning Providers ”Hotwires” site provisioning, by only creating site collection and database, but not apply template In code you then apply any template, and then apply any logic Example: Activate features, restrict sub-templates, create subsites, set security, create groups, add web parts... class MeetingWorkspaceProvisioningProvider : SPWebProvisioningProvider { public override void Provision(SPWebProvisioningProperties properties) { SPWeb site = properties.Web; string xmlPath = properties.Data; // provision Blank Meeting Template site.ApplyWebTemplate("MPS#1"); // do something potentially useful here } class MeetingWorkspaceProvisioningProvider : SPWebProvisioningProvider { public override void Provision(SPWebProvisioningProperties properties) { SPWeb site = properties.Web; string xmlPath = properties.Data; // provision Blank Meeting Template site.ApplyWebTemplate("MPS#1"); // do something potentially useful here }
WebProvisioned event receiver Gives you a hook into the provisioning process to execute arbitrary code. Event is asynchronous (but a good idea to set to Synchronous to avoid race conditions) Receiver can have Site or Web scope Site: called for every sub-site created in the site collection Web: called only for the sub-sites that are immediate children of the site where receiver is called Usage example: set Theme on sub-sites, add web parts... etc public override void WebProvisioned(SPWebEventProperties properties) { ThmxTheme theme = ThmxTheme.Open(properties.Web.Site, ThmxTheme.GetThemeUrlForWeb(properties.Web.ParentWeb)); theme.ApplyTo(properties.Web, false); properties.Web.Update(); base.WebProvisioned(properties); } public override void WebProvisioned(SPWebEventProperties properties) { ThmxTheme theme = ThmxTheme.Open(properties.Web.Site, ThmxTheme.GetThemeUrlForWeb(properties.Web.ParentWeb)); theme.ApplyTo(properties.Web, false); properties.Web.Update(); base.WebProvisioned(properties); }
Web Templates Created in Visual Studio as Element No direct tool support yet, but not much to it… Custom ONET is injected instead of referenced site definition, so no link to provisioned sites Scope can be Site (Sandboxed Solution) or Farm (Trusted solution) Supports publishing framework
Use the right tool for the job Often a combination is the right solution. The customizations you want to do often dictates approach. Use Web Templates whenever possible! What provisioning method is right? ”It Depends!”
Time for… DEMO!
Common ”gotcha’s” creating Web Templates Since stapling is not supported, be aware that features that would normally be stapled on an OOB site definition must be activated manually (e.g. Taxonomyfield feature) Web Template and the element it resides in must have same name If your Web Template has site scoped features, you must ensure these are activated when using template on sub-webs When provisioning sub-webs with PowerShell using Sandboxed Solutions you need to provision in two steps: 1) Create web, 2) Apply template Known issues: Doesn’t work with variations and content publishing Subweb and Locale doesn’t work! Bug if OS regional settings and installed language isn’t the same and provisioning “outside of UI” (Visual Studio or PowerShell) “Race conditions” with Content Type provisioning (CT hub)
Good Web Template practices Save the custom template name in a property bag on the SPWeb for future reference Ensure your site scoped features for example by calling them from web feature in ONET.XML Use Visual Studio –not save Site as Template- to create Web Templates Check what features are normally stapled to the OOB site definition you are mimicking and add them last at appropriate scope in ONET.XML
Key take-aways Web templates is just a new way of provisioning sites in SharePoint 2010 Prefer them over Site Definitions 99% of the time: B2B upgrades is easy (no link to manifest) V2V upgrades will be easier Works on SharePoint Online Scope is either Site (Sandbox) or Farm (Trusted) solutions Does not work with Site Variations, Content Publishing or similar sites where template selection is out of your control (think Meeting templates, My Sites etc)
Mirjam van Olst: Using Web Templates to create Site Collections Supported and unsupported scenarios for working with custom site definitions Vesa Juvonen: SharePoint 2010 and web templates Robert Bogue: Understanding SharePoint Branding Options Brian Wilson: Site Definitions versus Site Templates and deciding on the correct customization approach New Event Binding Functionality in SharePoint Foundation References
Thanks for attending session! Thanx for attending! See you at
Visual Studio 2010 SharePoint Power Tools Templates and extensions that provide a sandboxed Visual Web Part together with enhanced support for sandboxed compilation to help you develop SharePoint solutions even more productively. Mavention Cancel Adding SharePoint Project Items Disables the default behavior of automatically adding SharePoint Project Items to Features. CKS - Development Tools Edition (Server) The SharePoint 2010 Visual Studio 2010 Extensions project (CKSDEV) is a collection of Visual Studio templates, Server Explorer extensions and tools providing accelerated SharePoint 2010 development based on Microsoft's new SharePoint 2010 development tools. Imtech Get SPMetal Definition Extension Installs a Site Node Extension that allows you to generate the SPMetal Definition from the given SharePoint Site.