Sorry about the long title, but I thought it may help when someone is doing a search for such a topic. On with the show....

Invariably, if you are using Office SharePoint Designer (SPD) to create workflows, your power users are going to say 'Hey, I really like this but I want to have an Action that does xyz'. Nobody ever seems just satisfied with what we get out of the box, but that's the beauty of the Microsoft platform, its extensible!

So in part 1, we will talk about the first steps to creating a custom action.

ScenarioSuppose we have a situation where we have a car dealership that caters to customers that purchase fleets of vehicles. The idea here would be that whenever a new fleet customer wants to sign an order, we would want to take that order form and use it to create a unique site (or document library) for this client. I'd like to be able to create an action where I could pick from that would allow me to pick up the customers name from the document and use that to create my new document library.

Part 1 - Creating our Custom Action

1. First, we need to setup a sample site in WSS (3.0) or MOSS to use as our base site. Go ahead and create a site http://<yourmachineanddomain.com/FleetCustomers. Create a new document library named 'Fleet Customer Doc Lib'. In this document library, create a new custom column (single line of text) named 'Customer Name'.

A custom Action is actually just a custom workflow activity that is registered with the system using an .ACTIONS file, so now we will create a custom activity.

2. Create a new workflow activity library project in Visual Studio 2008 in some location on your machine for example 'C:\MSDNBlog\SPD' Give it the name 'CreateFleetDocLib'.

3. Rename Activity.cs to FleetDocLibActivity.cs. Open the code view to the activity.

4. Change the base class from SequenceActivity to Activity.

5. Create two Dependency properties (both strings):

Property Name

Data Type

Category

Description

Url

string

Input Property

Url of base site

CompanyName

string

Input Property

Used as doc lib name

This can also be done by using Insert Snippet > Other > Workflow > Dependency Property – Property.

6. To make sure we require validation on each of these entries (meaning we have to have input), put the following above each of the properties:

//we are going to create a new doc lib in the //sub-site, create a new empty template //type then set the type to be a doc library SPListTemplateType listTemplateType = new SPListTemplateType(); listTemplateType = SPListTemplateType.DocumentLibrary; lists.Add(CompanyName, "", listTemplateType);