Wednesday, March 10, 2010

Creating custom activity in Workflow Part – 3

Hi All,

In last two articles, we saw how to create basic activity and how to work with validations of properties.

If you haven't gone through previous parts, then i recommend you reading Creating custom activity in Workflow Part – 1 and Creating custom activity in Workflow Part – 2 post before continue reading here.

In this post, I am going to talk on Tool box item with respect to custom activity. When we want to initialize properties or want to perform any action when activity is being added (dropped) on visual designer, we can use toolbox item for this.

To achieve this functionality we have to implement two steps.

1) Create Toolboxitem class for custom activity deriving from ActivityToolboxItem class.

2) Add ToolBoxItem attribute to the custom activity class.

These two steps shown above are basic steps that you will find in all parts of this series. Because we have to perform above same steps (just inheritance is a difference) to achieve stuff for custom activity.

So let us go ahead and assign default birth date to our birth date property (I know it does not sounds anything practical, However as I said if we use simple example then it makes life easier).

One more important point to mention here is that we have to mark our class serializable and also we have to call deserialze in the constructor of the class. Reasons for this, well it is a topic of its own. I will explain it later. As of now, we will implement them to demonstrate our example and anyhow it’s merely two-three lines to write.

Go ahead and add class to our custom activity project. Name it CustomActivityToolBoxItem.



Then, go to the custom activity class and add System.ComponentModel which will help you to add attribute to the class.

Add the newly build assembly to the toolbox and drag and drop on visual surface and see the magic. You will see default birth date property being set by our code.



Read Creating custom activity in Workflow Part – 4 for more activities.

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 sharepointkings@gmail.com 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 sharepointkings@gmail.com