A lot of people have complained that access to the Virtual Labs that I mentioned earlier in my blog is very slow and unstable. So this tutorial that I’m about to give you is based on the case in Microsoft Virtual Labs. I’ve also had a lot of requests of posting example code for creating workflows in VS2008 Beta (last one from Stephen Korow). You’re about the witness an evolution in building workflows for Microsoft, no need for command line deployment, specific configuration of workflow features, and dealing with workflow and feature xml files.
What I’m about to show you I did and tested in the following environment:
· Microsoft Windows server 2003 R2 Enterprise Edition
· Microsoft Office SharePoint Server 2007 Enterprise Edition
· MS SQL 2005 Enterprise Edition
· Visual Studio 2008 Team Suite Beta 2
· Code was done in C# only
(Note: Not that you need this exact environment. Link to the source code and word template can be found at the end of this article)
1. In your SharePoint 2007 create a Document Library (unless you already have one) which is easily achieved by choosing “Create” from the “Site Actions” menu (located in the top right corner) and then choosing” Document Library”, give it a name and click “Create”.
Now you need to create a mock contract template in Word 2007 for your Document Library
2. When in your Document Library, click the Settings dropdown and select Document Library Settings.
3. On the Customize Documents page, locate the Columns section.
4. Create a Buyer custom column:
o Click Create Column.
o Type in the column name: “Buyer”.
o Select the type Single line of text.
o For the “Require that this column contains information setting” click Yes.
o Click Ok to add the new column.
5. Add two more columns: a “Seller” column that is type Single line of text and a “Purchase Price” column that is type Currency. Both columns should be required.

6. Return to the document library home page
7. On the New dropdown in the document library, click Document.
8. A new document appears in Word. Observe that there are text boxes for the custom columns from the document library:

9. On the Office menu click Save As. Save the document as %PATH OF YOUR CHOICE%\Contract.docx. If you are prompted to confirm saving to the new Word 2007 file format, click “Ok”.
10. Insert content controls for each of the server properties:
o Place the selection in the document where you want the content control to be placed.
o Select the Insert tab on the ribbon.
o Click Quick Parts, then click Document Property, and then click Buyer.
o Repeat these steps to add content controls in the document for the Seller and the Purchase Price properties.
o For now, leave the content controls empty – do not add text to them.
11. On the Office menu, click Exit Word. When prompted to save changes to the document, click “Yes”.
12. Return to the document library in Internet Explorer, click Settings and then select Document Library Settings.
13. On the “Customize Documents” page, locate the “Content Types” section and click the Document link.
14. NB. If you can’t locate the “Content Types” section, in the “General Settings” section locate “Advanced Settings” in there switch the radio button under “Allow management of content types” to “Yes”, now when you come back to the “Customize Documents” page you should be able to locate the “Content Types” section.
15. On the “List Content Type: Document page”, click the “Advanced Settings” link.
16. Select the Upload a new document template radio button and then click Browse. Browse to select %PATH OF YOUR CHOICE%\Contract.docx and then click Ok.

17. In Internet Explorer, return to the document library.
18. Upload a new document:
o In the document library, click the “New” dropdown and then click “Document”. Word starts and loads a new document based on the contract template you created.
o Fill in the values for Title, Buyer, Seller and Purchase Price. You can fill in the values on the document properties bar (just below the ribbon) or you can fill in the content controls: the end result will be the same.
o Once all required fields have been filled in, on the Office menu, click Save.
o Save the document with a filename of your choice to the document library. If you receive a message that the document must be checked in for it to be visible to others, click OK.
o On the Office menu, click Close. When prompted to check in the document, click “Yes”.
o In the Check In dialog, click Ok to accept the version defaults. Exit Word.
o Your new document appears in the document library. Notice that the Buyer, Seller and Purchase Price columns reflect the values you entered in the Word document.

19. You may upload additional documents if you wish.
20. Close Internet Explorer.
Now comes the fun part, creating the workflow itself
21. Start Visual Studio.
22. On the File menu, click New and then click Project. The New Project dialog appears.
23. In the list of Project Types, expand Visual C#. Expand Office and then select 2007.
24. Select the SharePoint Sequential Workflow project type.
25. Name the project ContractWorkflow, specify the default location and click “OK”.

26. The New SharePoint Workflow wizard appears. Change the workflow name to Purchase Contract, use your local site where you created your Document Library (eg http://localhost/yoursite) for debugging and click “Next”.

27. Click Next to accept the default lists for debugging.
28. h. Click Finish to accept the default conditions for how a workflow is started (the default selections are Manually by users and When an item is created).
29. The new workflow appears in the designer.

Add a CreateTask Activity to the Workflow
30. If the toolbox is not displayed, then on the View menu, click Toolbox.
31. From the SharePoint Workflow tab on the control toolbox, drag a CreateTask activity and drop it onto the workflow designer between onWorkflowActivated1 and the end of the workflow (
). The new activity is named createTask1 by default.

Note: If you can't find the Create Task Activity on the toolbox (which is more than likely with VS2008 Beta 2) you need to add it manually by right clicking on the toolbar (whichever section, "General" for example) and select "Choose Items" from the menu.
The following menu selection box will show:
Tick CreateTask option and OnTaskChanged while you're at it, you'll need it later.
32. Configure the TaskID property of createTask1:
o In the Properties window, click the ellipsis for the value of the TaskID property. The Bind ‘TaskID’ to an activity’s property dialog appears.
o Type the new member name myTaskId, ensure that the Create property radio button is selected and click OK.

33. Configure the TaskProperties property of createTask1:
o In the Properties window, click the ellipsis for the value of the TaskProperties property. The Bind “TaskProperties” to an activity’s property dialog appears.
o Type the new member name “myTaskProperties”, ensure that the Create property radio button is selected and click OK.
34. In the properties window, select the MethodInvoking handler. Type MyTaskCreation and press the Enter key. The code window appears.
35.