Hey!!! Welcome to Visit my Blog!!!

Monday, August 20, 2007

Code for Developed Own Activity Control

Notification Email :

Windows Workflow Foundation provides a visual interface for creating and hosting workflows that integrate seamlessly into line-of-business applications built on the .NET 3.0 Framework. Activity binding, one feature of Windows Workflow Foundation, allows an activity author to expose the properties of his or her activity to other activities at a workflow level. Once the properties are available at the workflow level, they can interact with the components that serve as the solution's user interface. This allows developers to set activity properties dynamically in a way that they are familiar with in a Visual Studio environment. This article walks through an example solution that demonstrates activity binding.

This article constructs a activity and shows how to use that activity within a workflow,There are a class [System.Workflow.ComponentModel.Activity] that you'll need to get to grips with in order to create an activity—in this example I'll create an activity called

[1] The first step in creating the example solution is to create a simple activity. In Visual Studio 2005, start a new solution with a Workflow Activity Library project. Visual Studio will provide a base activity (Activity1). Rename the activity to something suitable .System.Workflow.ComponentModel.Activity.

[2] dependency properties are configured as follows:

public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(string), typeof(SendMailActivity));
public string From
return ((string)(this.GetValue(SendMailActivity.FromProperty)));
this.SetValue(SendMailActivity.FromProperty, value);

[3] Now that the dependency properties have been defined, it is time to define the activity's function. This is done by overriding the Execute method of the activity. Simply add the following code.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
string url = System.Configuration.ConfigurationManager.AppSettings["url"].ToString();
MailAddress toAddress = new MailAddress(To);
MailAddress fromAddress = new MailAddress(From);
MailAddressCollection addresses = new MailAddressCollection();
MailMessage msg = new MailMessage(fromAddress, toAddress);

SmtpClient mail = new SmtpClient(MailServerUrl,25);

[4] Build Your Solution

[5] You can find This Actvity Component in your ToolBox Item.

[6] Now, You can drag and drop in your workflow state where you have need used to sent the notfication mail.

fig1:Repersenting State of State machine workflow.

<------SentMail Activity.

fig2:Dynamic Dependency Property:

<--From [Similarly you can craete more property eg:To,Subject,Email Body etc.]

Thanx & Regards

Rifaqat Ali

Sr. Software Engineer


MOSS 2007 Latest Update Videos