Friday, April 16, 2010

Working with declarative workflows Part 3

Hi All,

Let us continue our experiment with declarative workflow. If you haven’t read part 1 and part 2, I recommend you read them and enjoy reading further.
Now then we know how to create basic declarative workflow; we will move ahead and create declarative workflow that can accept parameters.

Go ahead and add one more XML file and this time name is “ConditionalDeclarativeWorkflow.xml” and then immediately change its extension to .xoml.

Now add code behind fine and name it ConditionalDeclarativeWorkflow.xoml.cs.

And start adding following stuff and do observe each condition that we have associated with xoml.

public partial class ConditionalDeclarativeWorkflow : SequentialWorkflowActivity
private string _BirthDate = string.Empty;

public string BirthDate

get { return _BirthDate; }
set { _BirthDate = value; }


private void CheckValidBirthDate(object sender, ConditionalEventArgs e)
if(_BirthDate == string.Empty) e.Result=false;

if (Convert.ToDateTime(_BirthDate) > DateTime.Today)
e.Result = false;
e.Result = true;
catch (Exception ex)
e.Result = false;


private void CalculateAge(object sender, EventArgs e)
if (_BirthDate != string.Empty)
DateTime dtBirthDate = Convert.ToDateTime(_BirthDate);

System.TimeSpan diffResult = DateTime.Today - dtBirthDate;

double age = diffResult.Days / 365;



Now how we used WFC in our previous post, we will use the same way here also. Go ahead and open command prompt.

And generate the DLL in this way. This time we are going to give two parameters to wfc.exe, first definitely a xoml and the other xoml.cs file.

Now add newly generated DLL to the reference of console workflow application.

Our workflow accepts the parameter, hence we are going to declare parameters and then invoke workflow.

Console.WriteLine("Waiting for workflow to complete");

Dictionary parameters = new Dictionary();

WorkflowRuntime runtime = new WorkflowRuntime();
WorkflowInstance instance = runtime.CreateWorkflow(typeof(ConditionalDeclarativeWorkflow), parameters);


Console.WriteLine("Workflow completed...");


So we have given input and we got the result, now let’s pass incorrect birthdate.

That is it. Hope you will try more complex example.

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