Monday, March 8, 2010

Creating custom activity in Workflow Part – 2

Hi All,

In my first post Creating custom activity in Workflow Part – 1 , we discussed about creating basic custom activity. Now as promised in this post, we will move a bit and hit the second topic of validation with custom activity.

When we gave input of birth date in first activity, we didn’t create any validations for it. This post will tell us how to create validation that will help us to validate the input user is providing to the parameters. So we will force user to provide correct birth date.

Bottom line is we can use the validation techniques in custom activity for each parameter that we define for our custom activity.

Adding validators consist of two steps.

1) We have to create a class which inherits from ActivityValidator Class.
2) Add ActivityValidator attribute to the custom activity class.

We have to override Validate method and we will return ValidationErrorCollection which hold all validation errors for birth date.

For validation logic, we will simply try to validate date against regular expression and if not matched, then we will throw the Error from our validator class.

Keep in mind that we are using the same custom activity that we’ve created in part 1. Hence if you haven’t gone through part 1, I recommend read it first and then carry on with this example.

So go ahead and add one class to the Workflow Custom activity project and name it CustomActivityValidator and inherit with ActivityValidator.

And then go to Custom Activity class and just add one attribute there on top of the class line and also add System.Workflow.ComponentModel.Compiler using statement.

Now just build the custom activity project again, and remove the previous custom activity on our console project and drag new (modified just now) activity to console application, and try to enter invalid date in property and valid property, and see. First we will enter valid date and then invalid date.

Read Creating custom activity in Workflow Part – 3 for furher reading.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to