Quick Start Guide

Create a new SharePoint web site via a Feature

Its simple to call SAF from a SharePoint Feature Receiver by creating the following Feature.xml file :

<?xml version="1.0" encoding="utf-8"?>
<Feature Id="{156E17A5-A7BA-4e1f-8A48-1BC341A7C658}" 
  Title="SAF Sample Feature - &apos;Action.CreateWebAction&apos;" 
  Description="Sample Feature illustrating how to call and run CreateWeb from a SAF Macro." 
  Version="" Hidden="FALSE" 
  ReceiverAssembly="Collaboris.Saf, Version=, Culture=neutral, PublicKeyToken=182db3eac6a9e195" ReceiverClass="Collaboris.Saf.Adapters.SafFeatureReceiver">
    <!-- Defines a SAF Macro containiing Actions to be run on Do and Undo -->
    <!-- Please visit http://www.collaboris.co.uk/Saf/Doc/default.html for more information. -->
    <Property Key="MacroFile" Value="Collaboris.Saf.Actions.Wss.Web.CreateWeb.macroTemplate" />
    <Property Key="InstanceId" Value="{156E17A5-A7BA-4e1f-8A48-1BC341A7C658}" />
    <Property Key="disabledo" Value="false" />
    <Property Key="disableundo" Value="false" />
    <Property Key="description" Value="New Web created by SAF" />
    <Property Key="lcid" Value="1033" />
    <Property Key="overwrite" Value="true" />
    <Property Key="template" Value="STS#0" />
    <Property Key="title" Value="New Web title" />
    <Property Key="url" Value="NewWeb" />
    <Property Key="useuniqueperms" Value="false" />
    <Property Key="webname" Value="New Web name" />
    <Property Key="id" Value="{47B640DD-64A9-493b-8445-789FC0D05FF1}" />
    <Property Key="stopondoexception" Value="true" />
    <Property Key="stoponundoexception" Value="true" />
    <!-- You can also define your own properties to be resolved by PlaceHolders in the Macro ... <Property Key="YourKey" Value="YourValue" /> -->

The points of note about the Feature Receiver above are as follows :

This line tells SharePoint where to find the SAF Assembly :
*ReceiverAssembly="Collaboris.Saf, Version=, Culture=neutral, PublicKeyToken=182db3eac6a9e195"*

This line tells SharePoint which .net class implements the Feature Receiver :

Lastly, we need to tell the Feature receiver exactly where the "Macro" resides. (Relative to the Feature.xml path).This is achieved by designating an "MacroFile":
*<Property Key="MacroFile" Value="Collaboris.Saf.Actions.Wss.Web.CreateWeb.macroTemplate" />*

As far as the Feature goes, thats it! You deploy the feature in the normal way, either by copying to the 12 hive, or deploying via a WSP.

Now to create the Web you need to give define an XML file in the following format. The file looks like this :
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net" default-lazy-init="true">
  <object id="MacroToProcess" type="Macro">
    <constructor-arg name="templateid" value="{839a4293-b076-485f-8478-9ea7d7605ea5}" />
    <constructor-arg name="actions">
      <list element-type="IAction">
        <object id="CreateWebd5" type="Action.CreateWebAction" lazy-init="true">
          <property name="DisableDo" expression="Func.Eval(&apos;${disabledo}&apos;)" />
          <property name="DisableUndo" expression="Func.Eval(&apos;${disableundo}&apos;)" />
          <property name="EntityList">
            <object id="WebInfob5" type="Entity.WebInfo" lazy-init="true">
              <property name="Description" expression="Func.Eval(&apos;${description}&apos;)" />
              <property name="Lcid" expression="Func.Eval(&apos;${lcid}&apos;)" />
              <property name="Overwrite" expression="Func.Eval(&apos;${overwrite}&apos;)" />
              <property name="Template" expression="Func.Eval(&apos;${template}&apos;)" />
              <property name="Title" expression="Func.Eval(&apos;${title}&apos;)" />
              <property name="Url" expression="Func.Eval(&apos;${url}&apos;)" />
              <property name="UseUniquePerms" expression="Func.Eval(&apos;${useuniqueperms}&apos;)" />
              <property name="WebName" expression="Func.Eval(&apos;${webname}&apos;)" />
          <property name="ID" expression="Func.Eval(&apos;${id}&apos;)" />
          <property name="StopOnDoException" expression="Func.Eval(&apos;${stopondoexception}&apos;)" />
          <property name="StopOnUndoException" expression="Func.Eval(&apos;${stoponundoexception}&apos;)" />

The file is best discussed in 2 parts (as illustrated in the comments).

Part 1 - The macro
This Part contains the Action(s) that you wish to do in your Feature. In this example, we have only one Action as we are just interesting in creating a web.

Part 2 - The Entities
Each Action can take zero or many Entities. Entities are simplye POCO's and nothing more. They are a way to pass parameters to the Action.

Last edited Feb 7, 2010 at 6:08 PM by MarkQjones, version 5


No comments yet.