But still at situations Designer Workflows not allow us to do certain Tasks, for an instance , performing cross site Tasks, like Creating a Document Library in a different site or Creating a new site on certain conditions.
• SharePoint Server 2010 Enterprise Edition
• MS SQL 2008 Enterprise Edition
• Visual Studio 2010 Ultimate
• Code was done in C# only
(Note: we don’t need the exact environment, but as such a similar one to get started)
Step: 1) Create a Project to support Activity Deployment to Farm
• Again Right Click “CreateSiteActivity” and click “View Code”.
• Now add a reference to
Microsoft.SharePoint.dll and Microsoft.SharePoint.WorkflowActions.dll located in ISAPI Library:
• Import the following NameSpaces in the code file:
This will how the code will appear now:
Before going further lets discuss some of the important terminologies:
Step :3) Some Introduction to WorkFlow Terminologies:
This will be boring a bit but very quickly please do read these lines as it will clear our process in a bigger way:
Dependency Property
Dependency properties provide a centralized repository of a workflow's state.
The DependencyObject is a hash table that stores the current values of any DependencyProperty that is applied to it.
Dependency Object Class:
An instance type of a dependency property can be bound to instance data, in which case the actual value is not determined until runtime.
You set this type of dependency property's value to be an ActivityBind to bind to the actual value that is accessed at runtime.
ActivityBind binds an activity property to any of the following:
• Another activity property.
• A field.
• A property.
• A method.
In Simpler Word:
Dependency Property provide a mechanism that allows SharePoint Designer to provide values for your custom action before you add your custom functionality.
To allow SharePoint Designer to pass values to your custom action when the workflow runs, you must create public properties inside your custom action. In this example, you will create a custom action that will create a new site within SharePoint whenever executed inside a SharePoint Designer workflow.
Before Writing any Dependency Property and its Binding Property, we have to think about our Inputs, so in this example here are the inputs:
SiteUrl: Where the site will be located.
SiteTitle: Title for the new site.
SiteDescription: Description for the new site.
SiteTemplate: Template to use to create the new site.
InheritPermissions: True, if the new site will inherit permissions from its parent site.
For each field, you create a property in your custom action to allow the users to specify these values when designing their workflow in SharePoint Designer.
When creating properties for a custom action, you create the property itself and a matching DependencyProperty. The DependencyProperty class allows SharePoint Designer to bind the property to the UI in the workflow wizard, where the user specifies the values of these properties in the workflow being created.
Note: Please follow the Syntax we will use while Creating a Property and a Matching Dependency Property, there is Matching Relation require in both of these Names.
Add the following code to create a property and DependencyProperty for SiteUrl:
Parameters it takes are : 1)String Name of the associated Property, Type of Property, Type of Owner(Activity Class Name)
Now for a while just think on what we have written:
Step:5) Complete Rest of Dependency Properties Simmilarly
simmilarly complete the Dependency Properties for rest of inputs we discussed earlier and code should now look like this:
Step:6) Execution of Main Action
Whenever in Workflow the pointer reaches to the Activity then There is an entry method which executes and this method/function is Execute :
We need to override this function to write the functionality of our activity:
This function returns an ActivityExecutionStatus which is an enum containing values. And takes executionsyntax as parameter.
For getting refference to current site , we will use _Context property that we defined above
Step:7) Code to insert in Execute Method:
Note: If an error occured then we have used ISharePointService to logtohistory list whatsoever error occurs.
Step : 8) Create ACTIONS file
NOTE:Before reading the next lines first Sign the Assembly and run "sn.exe -T 'Path to Dll'" command to get the PublicKeyToken Value of CreateSiteActivity.dll
Next Step is to Create an Action File, this file is require to tell Designer how the Activity will appear in UI to the USER, this will make the custom activity to appear in the Wizard.
An ACTIONS file is an XML file that is used by SharePoint Designer's workflow wizard to provide a user-friendly experience for configuring actions. Every action must be configured in an ACTIONS file before it can be used in SharePoint Designer. By default, there is only one ACTIONS file, located at
{14 Hive}\TEMPLATE\1033\Workflow\WSS.ACTIONS, and it contains an entry for each of the built-in actions in Windows SharePoint Services.
for a complete refference of this file please visit this msdn article:
http://msdn.microsoft.com/en-us/library/bb897811.aspx
Step:9) Deployment Process
Deployment Process Consists of Four Sub Steps:
1)Sign The Assembly and Get The Public Token and place it in the ACTIONS file:
Right Click “CreateSiteActivity” Project and then go to Properties and then in “Signing”, create a new key name it “CreateSiteActivity”, then BUILD the Project and later Sign the assembly using:
Sn.exe –T “path to CreateSiteActivity.dll”
Note the PublicKeyToken and modify the Actions file accordingly.
2)Place the ACTIONS file to the Worklfow Mapped Folder of SharePoint 14 Hive:
In the CustomActivityDemo project Add a SharePoint Mapped Folder to Template /1033/Workflow
i.e{SharePointRoot}/Template/1033/Workflow and save the above ACTIONS file, with ACTIONS as extension.
3)Deploying CreateSiteActivity DLL to GAC and Create Safe Control in Web Config of the Web Application.
1)Expand the Package Item in the CustomActivityDemo Project,
Uncomment Feature Activated Block.
If you see the properties of SPWebAPPlication Instance then you can see a collection WebConfigModifcations:
Now we have to add a new webconfigmodifcation to this collection , to do so create an Instance of SPWebConfigModification class:
SPWebConfigModification modification = new SPWebConfigModification();
Now we will initiate these properties of Modification:
Entire Code will appear as this:
Next Build, Package and Deploy your solution.
Step: 10) Test the new Action
Next open the site which we used for testing this project in SharePoint Designer and Create a New List Workflow on any of List (take Task).
And in List Actions you can see our newly created activity:
It will Work as it did at my end. Please test yourself and use it in your daily workflow cycle.
Hope it will help and Workflow Activities creation will be now a simple process for you all.











