Creating Custom Activity for SharePoint Designer

 

Hey guys,

Today i want to show you how to create a new Custom Activity for SharePoint.

 

System Requirements:

-          VS 2005/2008

-          Windows Workflow Extensions for VS

-          WSS 3.0 SDK for VS

-          SharePoint 2007 Server or WSS 3.0

 

How to start:

First of all open your Visual Studio and navigate to File-> New-> Project -> Workflow Activity Library

A new Project with one Activity will be loaded. Now we can begin to develop our Custom Activity for SPD (SharePoint Designer).

At first we have to specify the Dependency Properties, these are the Properties which interacts with SPD Workflow Wizard. The Declaration is as following:

private static DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(YourCustomActivity));

 

The next step is to define the properties for internal use. There are several Options which can be given to the property.

 

[Description("Message ")]

[ValidationOption(ValidationOption.Required)]

[Browsable(true)]

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

public string ToList

{

      get

      {

  return ((string)(base.GetValue(YourCustomActivity.MessageProperty)));

      }

      set

      {

  base.SetValue(YourCustomActivity. MessageProperty, value);

      }

}

 

So now we are ready for implementing our CustomActivity. So you have just to override the Execute method. Here is a little example which only writes an eventLog entry to the application log.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

   try

     {

EventLog.WriteEntry("Workflow Test", this.Message,     EventLogEntryType.Information, 9999, 4);

 

            return ActivityExecutionStatus.Closed;

     }

     catch (Exception ex)

     {

            return ActivityExecutionStatus.Faulting;

     }

}

 

The last step which we have to do with coding is to rename the SequenceActivity to Activity.

 

public partial class YourCustomActivity: Activity

 

Now we have to sign the assembly with a strong name and build the solution. I will describe the Deployment procedure for a custom Activity in another post.

 


Posted Jul 22 2008, 05:31 PM by Nadine Storandt

Comments

elyes85 wrote re: Creating Custom Activity for SharePoint Designer
on 08-02-2008 10:01

First, I would thank you about your interesting article about custom activity.

By the way I have a problem, I give me an idea to resolve it please !

I wanna to develop a custiom activities which encapsulate SharePoint activties, with adding properties,  like, CreateTask, OnWorkflowActivated, ...like that the end user can insert those activities without manipulate C# code, I did it with those activities but I found a serious problem with DeleteTask activity because it need th TaskId in RunTime which is not clear for me !

Thanks for your coorporation !!

 Thanks !

Nadine Storandt wrote re: Creating Custom Activity for SharePoint Designer
on 08-04-2008 12:26

First, thanks for your support.

I'm not sure if I understand your problem. But here is my opionion what's about Input Parameters for your Workflow?? If you define an parameter which inlcudes the current list item from which the workflow will be started. Then you must have the property TaskId at runtime.

Alexander wrote re: Creating Custom Activity for SharePoint Designer
on 11-21-2011 14:50

Hi Nadine,

for peoples who wish to avoid coding of activities, we are offer the set of 180 ready to use sharepoint workflow activities, including the ones to execute c#/vb.net/powershell code from workflows.

Free download of HarePoint Workflow Extensions at www.harepoint.com

Product also contains about 30 freeware activities.

WBR,

Alexander

developers.de is a .Net Community Blog powered by daenet GmbH.