Skip to main content

Blog

Go Search
Home
Blog
Playground
Code Snippets
TweakSP
Contact Me
  

www.iwkid.com > Blog
 
November SharePoint User Groups

Over the next two weeks I'll be presenting at THREE different SharePoint User Groups!

I am super excited for the chance to see some new User Groups in action!  I'm also excited that this month we'll be testing out a way to record our MNSPUG presentations to make them available for online viewing after the event!

Templates and SharePoint Sites - 4 of 4

Best Practice

We've covered several different approaches to creating templated SharePoint Sites, now I'll bring everything together and we can walk through what I would recommend as a best practice.

 

Goals

First let's talk through my goals.  You may find that our goals differ and, in that case, one of the approaches on my previous post would work fine in your scenario.

  1. Allow Site Administrators to create a site using the out of the box site creation screens
  2. Support Feature Stapling for future updates
  3. Create no dependencies on the SharePoint Farm:
    • The Site "Template" can be removed at any time without affecting previously created sites
    • Minimal impact projected during future platform upgrades

 

Almost There

At first glance we can get pretty close using the Feature Stapling approach outlined in my previous post.  The biggest barrier is the creation of a new Site Definition which we have identified as an unacceptable dependency.  If we want to use Feature Stapling, we need a unique Template Name to point to...  If we create a unique Template Name, we have a dependency...

 

The Keystone

The piece that makes it all possible:  SPWebProvisioningProvider.  A Provisioning Provider can be specified in a Site Definition's webtemp*.xml file.  In the configuration element, you can specify the ProvisionAssembly, ProvisionClass, and ProvisionData attributes.

Hold it right there, does that mean we're creating a Site Definition?  I thought they were the root of all evil?  Not so fast, my friend:

If you implement your own class that inherits from SPWebProvisioningProvider, you can use it to call the ApplyWebTemplate method of a Web which allows you to manually provision one of the out of the box Site Definitions!  That means you get your unique Site Template Name but when the site is created it THINKS it is an out of the box Site Definition!

As my buddy Tom used to say, NOW how much would you pay?  :-)

 

The Solution

  1. Create the webtemp*.xml (using the ProvisionAssembly and ProvisionClass attributes):

    webtemp
  2. Create the Provisioning Provider (which applies the "Blank Site" Site Definition):

    SPWebProvisioningProvider
  3. Create any Feature Receivers and Feature Staplers
  4. Wrap everything into a SharePoint Solution and you're done!

 

Post-Deployment you can make updates by updating your Feature Receiver or the code in your provisioning provider.  Also, if you're done making sites of that type, go ahead and uninstall your SharePoint Solution: Your sites were created using out of the box Site Definitions so there is no leftover dependency.

 

Conclusion

This series of posts covers a lot of information and skims over even more.  I intend for it to be an evolving series and will be adding code samples and follow-up posts.  For the latest, keep an eye on the series introduction or subscribe to this post's category.

Templates and SharePoint Sites - 3 of 4

Approaches and Comparisons

Now that we've taken a look at some of the related technologies and covered some background, let's dig into the different approaches for creating templated SharePoint Sites and see what works and doesn't work for different scenarios.

 

Overview

Custom Site Definitions Create a custom Site Definition and deploy it to your SharePoint Farm.
Site Templates Save a configured SharePoint Site (which was based on a Site Definition) as a Template.
Feature Stapling Create a Feature that customizes a SharePoint Site upon activation.  Create a second Stapling Feature that associates your customization feature with an existing or new Site Definition.
Programmatic Site Creation Create a Web Part or a custom Application Page that initiates the programmatic creation of a SharePoint Site.

 

Custom Site Definitions

Usage Scenario

As a SharePoint Developer+Administrator, you want to create a template for "Project Sites."  Project Sites will be created over and over again and will always contain the same base lists and libraries.  Using Visual Studio you create a Custom Site Definition, wrap it into a SharePoint Solution, and deploy it to your server.  Site Administrators can now see "Project Sites" as an available template when they create new SharePoint Sites.

Realities
  • A Developer must be involved to create the required XML files and to wrap the customization into a SharePoint Solution
  • A Server Administrator must be involved to deploy the custom Site Definition via Solution deployment
Pros
  • Highly documented in the SDK, in books, and on the googlesphere
  • Visual Studio Extensions for SharePoint have project templates to "help" you
  • Allows you to take advantage of Feature Stapling (see below)
  • Custom Site Definitions appear in the list of "Site Templates" that Site Administrators choose from when creating sites
Cons
  • Creates a dependency in your environment
    • Sites created based on your custom Site Definition will not work if you uninstall the Site Definition.  Your custom Site Definition will need to exist on your SharePoint Farm (possibly now and forever, depending on upgrade paths/etc)
    • When SharePoint v-next comes out, instead of learning about new functionality and how it can positively affect your environment and business, you will be forced to learn about how to upgrade your Site Definitions into a v-next environment
    • Site Templates are based on sites that were created from Site Definitions.  If you create a custom Site Definition, create a site based on that custom Site Definition, customize that site, and then save that site as a template you will only be able to use that Site Template on SharePoint environments that have your custom Site Definition
  • Site Definitions can be difficult to debug during development
  • Updating your custom Site Definition to contain an additional List or Library will not update sites that have already been provisioned with your Site Definition (and, is also technically unsupported)
  • You will never regain the time you spent learning the ONET.XML file.  There is no other place in SharePoint where that knowledge is directly applicable

 

Site Templates

Usage Scenario

As a SharePoint Site Administrator, you want to create a template for "Department Sites."  You create a sample site based on the "Blank Site" Site Definition and then customize the sample site to contain the lists, libraries, and Web Parts you would like to have on each Department Site.  Once you're done, you save the site as a template and create 4 Department Sites based on your custom template.

Realities
  • A Site Administrator can do this, no Developer/Server Administrator assistance or involvement is required
  • Your custom Site Template can also be shared with other SharePoint Farms (as can other people's Site Templates, e.g., the Application Templates for WSS)
Pros
  • Very quick and easy to create
  • Portable and easy to deploy across environments (* Note the dependency above if the site was based on a custom Site Definition)
  • Site Templates appear in the list of "Site Templates" that Site Administrators choose from when creating sites
  • No Dependencies based on your Site Template's .stp file.  If a site is created based on your Site Template and then you remove your template from the Server's Site Gallery, your site instance will still work
Cons
  • Not every customization is saved - I have not yet seen a definitive list of what works and doesn't work when you save a Site Template but I do know that some things do not come over as customized.
  • Bugs / unexpected behavior should be expected with heavily configured sites (Web Part properties, custom Views, etc)
  • Any customized pages are duplicated when a site is created based on a Site Template
    • If you updated a page in SharePoint Designer
    • If you applied a Theme (that's right - all those images and .css files)
  • Site Templates cannot really be debugged as they are built using SharePoint's Web Interface

 

Feature Stapling

Usage Scenario

As a SharePoint Developer+Administrator you want to create a template for "Project Sites."  You know that the definition of a "Project Site" is going to evolve over time so you want to make it as flexible as possible.  You decide to use Feature Stapling and to implement your site customizations as custom code wrapped in a Feature Receiver.  Because Feature Stapling maps features to Site Definitions, you start by creating a custom "Project Site" Site Definition.  Using MSDN as your guide you create a new Site Definition by creating a copy of the "Blank Site" Site Definition.  Your "Project Site" Site Definition has its own Template Name and so it can now be targeted for Feature Stapling.  You wrap your Site Definition, Features, and Feature Receiver code into a SharePoint Solution and deploy it to your server.  Site Administrators can now see "Project Sites" as an available template when they create new SharePoint Sites.

Realities
  • A Developer must be involved to create the required Features and Receivers and to wrap the customizations into a SharePoint Solution
  • A Server Administrator must be involved to deploy the customizations via Solution deployment
Pros
  • Implementation can be (supportably) updated by deploying an updated Feature Receiver  (existing sites would not be updated by default but the feature could be designed to allow for re-activation via script/etc)
  • No need to customize the Site Definition or the ONET.XML file.  Your knowledge is focused on Object Model development which can be reused in other areas of SharePoint Development
  • Easier debugging because you can simply activate a feature to test your site customization logic (as opposed to creating an entire site)
  • Custom Site Definitions appear in the list of "Site Templates" that Site Administrators choose from when creating sites
Cons
  • You are still creating a dependency because of your custom Site Definition (required to target specific types of sites)
  • You may have to dig deeper into the object model than you'd like to create things like custom views, etc (which, at first glance, look easier with Site Definitions)
  • You may run into race conditions if dealing with things that are provisioned as part of your Site Definition.  You would potentially have to create a test for race conditions in your Feature Receiver or else use the ExecuteUrl property as an alternative for those customizations.  For example:
    • A Site's default.aspx page is provisioned by most Site Definitions.  Your Feature Receiver may get kicked off before the page gets fully provisioned
    • Your base Site Definition could contain a List.  If your Feature Receiver expects that list to be there, again your Feature Receiver may get kicked off before the list gets fully provisioned

 

Programmatic Site Creation

Usage Scenario

As a SharePoint Developer+Administrator you want to develop a way to consistently create "Project Sites."  You have identified a parent site that will contain children "Project Sites" and you have identified what lists, libraries, and Web Parts make up a "Project Site."  You create a custom Web Part that creates a site using one of the out of the box Site Definitions and then programmatically add lists, libraries, and Web Parts to the newly created site.  You wrap your custom Web Part in a SharePoint Solution and deploy it to your server.  Users that want to create a "Project Site" are required to use your Web Part to create "Project Sites."

Realities
  • A Developer must be involved to create the required Site Definition, Features, and Receivers and to wrap the customizations into a SharePoint Solution
  • A Server Administrator must be involved to deploy the customizations via Solution deployment
  • Because the approach uses a non-standard Site Creation process, users could be confused and may:
    • not know where to go to create project sites
    • create sites that don't use the correct "template"
Pros
  • Complete control without dependencies
  • No need to customize the Site Definition or the ONET.XML file.  Your knowledge is focused on Object Model development which can be reused in other areas of SharePoint Development
Cons
  • You may have to dig deeper into the object model than you'd like to create things like custom views, etc (which, at first glance, look easier with Site Definitions)
  • User Experience is non-standard

 

Summary

It is clear that there are plusses and minuses to each of these solutions.  In my next post I'll talk about how you can use pieces from each solution (and a little something new) to create templated SharePoint Sites using my recommended Best Practice.

Templates and SharePoint Sites - 2 of 4

Definitions and Backgrounds

When we talk about "templates" in SharePoint there are a number of things we could be talking about.  In an effort to clear up some confusion I thought I would list some of the related technologies and talk about how they all fit together.

Creating Sites

First of all, it is important to note that creating a SharePoint Site is Two-Step Process.  If you want to see that in action, open up SharePoint Designer and get ready to create a new SharePoint Site.  Then, open up Fiddler and then create your new site.  In Fiddler you should see two specific command types go by:

  1. A call to /_vti_bin/_vti_adm/admin.dll.
    Create Service
    This uses FrontPage RPC's "Create Service" method which creates a site.  If site creation was interrupted at this point and you browsed to the site you would be prompted to select a template.
  2. A call to /_vti_bin/owssvr.dll.
    Site Provision
    This uses WSS RPC's "Site Provision" command to specify which Site Definition should be applied.

The best way to think of it is when you create a site you are creating the service (it exists but is completely empty) and then provisioning the site (has a Site Definition applied):

Site Creation Process

It is important to note that once a Site Definition has been provisioned it CAN NOT BE CHANGED outside of an upgrade scenario.

 

Site Definitions

At the core of every SharePoint Site is a Site Definition.  WSS ships with 12 Site Definitions by default (although some of those are hidden).  You can take a look for yourself at the WEBTEMP.XML file on your SharePoint Server in the following directory:  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\1033\XML

 

Site Templates

Site Templates can be created by Site Administrators through SharePoint's Web Interface.  They essentially save the changes that have been made to a site since it was provisioned.  The important thing to note here is that a Site Definition has already been applied.  Site Templates are saved as .stp files which are really just CAB files that contain a manifest.xml and any of the site content that was saved with the template.

Site Template as CAB

 

Feature Stapling

Feature Stapling allows you to associate a feature with a Site Definition.  This means that during the provisioning stage of site creation a feature will be automatically activated on the site.  The important thing to note here is that features are stapled to specific Site Definitions by their Template Names.

 

 

Now that we've got some common terms and a little background, let's look at the different approaches to creating templated SharePoint Sites.

Templates and SharePoint Sites - 1 of 4

Introduction

Yesterday Joel wrote a post titled "Just SAY NO to Creating Custom Site Definitions."  This has been a subject I've given a lot of thought to lately so I thought now would be a good time to put some of those thoughts into writing.  Because it it is such a big topic, hitting many different SharePoint technologies/areas, I have split it into several core posts and plan to add follow up posts which I will link to from here.

Core Posts:

  1. This introduction post
  2. Definitions and Background
  3. Approaches and Comparisons
  4. Best Practice

 

My Related Posts:

 

Other Related Posts and Resources:

  1. Just SAY NO to Creating Custom Site Definitions - Joel Oleson
  2. SPWebProvisioningProvider
Cascading Drop-Downs in InfoPath

Here's a fun trick if you've ever wanted to have related/cascading drop-downs in InfoPath:

1) Create the data source for your drop-downs.  Here I am using an XML file:

image

2) Add your data source as a resource file:

image

image

3) Add a data connection for your resource:

image

image

image

image

4) Add your drop-downs to the form:

image

5) Configure the data source for your parent drop-down:

image

6)  Configure the related drop-down:

image 

This is where it gets tricky.  We need to add a pretty complex filter here.  First click on Filter Data:

image

Then add a filter:

image

Choose to select a field or group:

image

Change the data source to Main and select the parent field:

image

Then you'll have most of the filter defined:

image

Now switch to the expression view:

image

And update your expression:

image

In this instance we're saying that the title attribute of the parent state element should match what was selected in the parent drop-down.

7) To make sure the drop-downs work properly you'll want to clear the related field every time the parent field gets changed.  To do that, add a rule to the field:

image

Select Rules:

 image

Add the following rule with an action to set the related field's value = to ""

image

8) Test the form by selecting preview:

When I select MN I should get a list of just the MN cities:

image

After selecting a city:

image

When I change the state to WI, Bloomington is unselected:

image

And when I hit the city drop-down again, I should get a list of just the WI cities:

image

You can download my example XSN here.

Visual Studio Extensions for SharePoint and x64?

So after rebuilding my machine I decided to go with Vista x64 again since SharePoint v-Next won't support 32 and I want to make sure I'm ready.  So I got Vista reinstalled and then added SQL 2k8 and VS2k8 SP1 and things were going pretty well!

Today I tried installing the updated Silverlight Blueprint for SharePoint and when I tried opening them I got an error:

image 

From what I can tell, the project type it is trying to open is a project type defined in the Visual Studio Extensions for SharePoint.  So, reluctantly, I went to download that install.  Imagine my surprise to learn:

"This download does not work with an x64 OS. We currently recommend a x86 development machine for SharePoint development when targeting x64 OS for test and production. Output binaries are all .NET assemblies so you can reasonably expect all .NET assemblies built on the x86 dev box to still work on your x64 OS test and production machines. The CLR will JIT compile the .NET assembly on each target machine and will optimize for x64 OS when run on that architecture. Testing on x64 after doing development on x86 is still recommended."

You can imagine my frustration...  Not only are the Visual Studio tools WORSE than useless IMHO - I can't even install them on the architecture that Microsoft recommends we all run to.

I was ready to write a monster post venting my frustration but I found that Brian Madsen has saved me the trouble:

http://msmvps.com/blogs/brianmadsen/archive/2008/07/02/visual-studio-2008-extensions-for-windows-sharepoint-services-epic-fail.aspx

Brian, I 100% agree.

Online Workshop

Next week Bob Mixon (of Mixon Consulting, SharePoint Beagle and SharePoint MVP fame) is delivering an online workshop titled 'Learn to Build "Real World" SharePoint Solutions.'  The workshop includes a class workbook (in PDF), a full VPC, and course delivery by Bob over 4 days (8:00am PST till 11:30am PST).

Learn To:

  • Build "Real World" Solutions using SharePoint out-of-box features, without Visual Studio.
  • Create site and navigation structures that can be used by both the contributor and consumer.
  • Build a Taxonomy and learn how to Apply it to SharePoint.
  • Reduce, if not eliminate, Document Duplication.
  • Configure Search so it Delivers Relevant Results.
  • Understand security, how it works and techniques for correctly applying it.
  • Automate business processes with workflow.
  • Create a Request and Site Provisioning Solution.
  • Utilize SharePoint to manage your implementation.
  • Increase confidence in your ability to successfully create solutions that will be adopted by users.
  • Understand key factors in making a build versus buy decision.
  • Much more...

There is a $100 savings (standard registration is $895) if you register before Friday, September 12th, 2008 but Bob has also supplied me with an event code that will save you an additional $50.  You can use the code RMITCHELL when registering at the following URL:  http://www.regonline.com/20080916-PAD-VL

Full course details available here:  http://mixonconsulting.com/training-event-descriptions/pad-vl/

Kris Nyreen spotlighted on Spaghetti Code Podcast!

Kris Nyreen (of Branding SharePoint fame) was recently spotlighted on the Spaghetti Code podcast.  You can hear Kris (the devigner) speak on designing and developing with Silverlight on the podcast here:

http://slickthought.net/post/2008/08/Spaghetti-Code-Podcast---Seeing-the-Silverlight-with-Kris-Nyreen.aspx

A look ahead

Here's a quick look at some events coming up in the next few weeks:

1 - 10 Next

 ‭(Hidden)‬ Admin Links