Use Visual Studio 2010 to Create a Site WorkFlow

You can use Designer to visually create or modify a workflow. You can also use Visual Studio 2010 if you need the workflow to perform a customaction.

Here we want to create a “list workflow” that applies to “task” list, that add the string “[Work Item]” to the title of the task item that trigger the workflow.

Launch Visual Studio 2010, create a new project, based on Sharepoint 2010’s “Empty Sharepoint Project” template. Change the name to “AddToTitle”, and save.

Select a local site for debugging use; select farm solution since this is a workflow template.

Right click the project name (“AddToTitle”) in the solution explorer, Addà New Item. Select Sharepoint 2010’s “Sequential Workflow” from the dialog box.

Associcate the workflow with the Task list.

After that, in the design view, you will see a diagram like this. You’re ready to drag and add additional actions to the workflow.

Look in the toolbox on the left for a tab that says “Windows Workflow v 3.0”, expand the tab. We want to add a “Code Activity” to the workflow so the code can modify the title for us after the workflow starts. So Drag the “Code” under Windows Workflow v. 3.0 to the diagram:

Then you will see this. A code block has been added. The exclamation mark means you need to fill in some code now. Double-click the code block.

In the code view, look for the codeActivity1_ExecuteCode method, and add two lines of code:

Save, rebuild and deploy the solution to your Sharepoint 2010 server.

Go to your Sharepoint web site, add a new item to the Task list. Initially the title of the Task remains what you entered; refresh the browser and you will see the title updated by the workflow.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: