Download Custom Web Templates - SharePoint Bruger Gruppe (SPBG)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Who am I?
Anders Rask
SharePoint Solution Architect, ProActive A/S
Community moderator on sharepoint.stackexchange.com
@AndersRask
http://dk.linkedin.com/in/arask
http://sharepoint.stackexchange.com
http://sites.wizdim.com/andersrask
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!
Template Provisioning methods
 Site Templates
 Site Definitions
 Feature Stapling
 Provisioning Providers
 WebProvisioned event
 Web Templates
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
<FeatureSiteTemplateAssociation Id=”[guid]>"
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
class MeetingWorkspaceProvisioningProvider : SPWebProvisioningProvider
 In
{ code you then apply any template, and then apply any logic

public override void Provision(SPWebProvisioningProperties properties)
{
Example:
Activate features, restrict sub-templates, create subsites, set
SPWeb site = properties.Web;
string
xmlPath
= properties.Data;
security,
create
groups,
add web parts...
// 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.
void WebProvisioned(SPWebEventProperties
properties)
 public
Event isoverride
asynchronous
(but a good idea to set to Synchronous
to avoid
{race conditions)



ThmxTheme theme = ThmxTheme.Open(properties.Web.Site,
ReceiverThmxTheme.GetThemeUrlForWeb(properties.Web.ParentWeb));
can have Site or Web scope
theme.ApplyTo(properties.Web, false);
Site:properties.Web.Update();
called for every sub-site created in the site collection
base.WebProvisioned(properties);
}Web: called only for the sub-sites that are immediate children of
site where receiver is called
 Usage example: set Theme on sub-sites, add web parts... etc
the
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
What provisioning method is right?
”It Depends!”
 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!
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)
References
Mirjam van Olst: Using Web Templates to create Site Collections
http://yux.dk/1a
Supported and unsupported scenarios for working with custom site definitions
http://yux.dk/1b
Vesa Juvonen: SharePoint 2010 and web templates
http://yux.dk/1c
Robert Bogue: Understanding SharePoint Branding Options
http://yux.dk/1d
Brian Wilson: Site Definitions versus Site Templates and deciding on
the correct customization approach
http://yux.dk/1e
New Event Binding Functionality in SharePoint Foundation 2010
http://msdn.microsoft.com/en-us/library/ee539983.aspx
Thanks for attending session!
Thanx for attending!
See you at http://sharepoint.stackexchange.com 

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.
http://visualstudiogallery.msdn.microsoft.com/8e602a8c-6714-4549-9e95-f3700344b0d9

Mavention Cancel Adding SharePoint Project Items
Disables the default behavior of automatically adding SharePoint Project Items to Features.
http://visualstudiogallery.msdn.microsoft.com/9c7c4a73-3558-4712-a65c-badf070e4abc

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.
http://visualstudiogallery.msdn.microsoft.com/ee876627-962c-4c35-a4a6-a4d89bfb61dc

Imtech Get SPMetal Definition Extension
Installs a Site Node Extension that allows you to generate the SPMetal Definition from the given SharePoint
Site.
http://visualstudiogallery.msdn.microsoft.com/1a7fc8c2-8cdb-414b-b7bb-9c25897bf78b