Creating Advanced Workflow Solutions with Visual Studio and InfoPath

The Visual Studio Workflow Designer provides a project system for developing workflow solutions. It allows you to quickly define a workflow graphically by dragging activities from the toolbox onto the design surface, and provides code-beside for business logic, a mechanism for compiling work-flows, and integrated workflow and code debugging.

Microsoft Office SharePoint Server 2007 Workflow Developer Starter Kit installs additional project templates and a Toolbox and Designer that developers can use to build custom Microsoft Office SharePoint Server 2007 workflows. Windows Workflow Foundation provides the Visual Studio 2005 Designer for Windows Workflow Foundation, which is an add-in to the Microsoft Visual Studio 2005 development system.

Adding Custom Activities and Conditions

Developers can add activities and conditions to the SharePoint Designer Safe List. To do this:

1.
Develop the activity or condition.

2.
Compile the activity or condition as a strong-named assembly.

3.
Deploy to the global assembly cache.

4.
Add the activity or condition to the action safe list in the web.config file.

5.
Add rules and parameters for the sentence that represents the activity or condition in the user interface to the WSS.Actions file. The WSS.Actions file is a markup specifying the appearance and performance of the activity or condition.


InfoPath provides a rich-forms development environment that integrates nicely with Visual Studio. This chapter walks through a detailed tutorial that will introduce you to how these capabilities all come together to develop advanced workflow solutions.

Tutorial: Build a custom workflow

This tutorial will guide a beginner-to-intermediate–level developer through creating a workflow in Visual Studio for MOSS 2007 and using InfoPath to control the state of the workflow. You will use Visual Studio to facilitate the action of sharing data between InfoPath forms. The workflow will be attached to a Wiki document library, and when a new Wiki page is created, the workflow will assign a task to a user to moderate the Wiki content. This user will be assigned according to the information entered into the initialization form you create with InfoPath. The assigned user will receive an e-mail containing the normal task assigned information as well as the Wiki page content that you will append to the e-mail body. The user then must verify in the second InfoPath form that he or she has completed moderating the Wiki before the task will be set to complete and the workflow set to finish. In order to create custom workflows with this level of control, you must use Visual Studio to pass the information between the forms and also to modify the e-mail sent out when creating a task to include the Wiki content.

Prepare your environment

On the Client: Install InfoPath 2007 and Office 2007.

On the Server: Install Visual Studio 2005, Visual Studio Extensions for Windows Workflow Foundations, and the 2007 Workflow Developer Starter Kit.

Create the Visual Studio project

To create a Visual Studio project, follow these steps;

1.
Open VS 2005 and choose File New Project.

2.
In the New Project dialog box, under Visual C#, select SharePoint Server and then SharePoint Sequential Workflow Library, as shown in Figure 8.8.

Figure 8.8. New Project dialog box


3.
Name your project “Wikiworkflow” or another name that will help you identify it later and enter a location for the files and a name for the Solution. Keep the Create directory for solution box checked and click OK.

4.
On the right-hand side of VS2005, in the Solution Explorer, right-click Workflow1.cs and select View Designer to the see the graphical workflow designer tool.

Wiki site and list creation

Create the Wiki site and list to use for the example.

1.
From your portal or a team site, click View All Site Content above the left navigation.

2.
Click Create, and under the Libraries heading click Wiki Page Library.

3.
Call it something like “WF Wiki,” enter a description if you want, and click Create. Your new Wiki site appears as in Figure 8.9.

Figure 8.9. New Wiki site


4.
A SharePoint Wiki is simply a set of pages in a document library, and you will assign your workflow actions to this library. Your document library is located at http://(Yourservername)/(Yourwikisitename)/forms/allpages.aspx. Using my example, it was created at http://mossdev/WF%20Wiki/Forms/AllPages.aspx.

InfoPath form #1 creation

You will create two InfoPath forms for this workflow example. You need one form to kick off the workflow, which will assign the user to the task of viewing the links created in the Wiki and then searching for duplicate content. The second form is a moderation form that will list all of the Wiki links for the user, along with links to the corresponding created page.

1.
Open InfoPath 2007.

2.
Select Design a Form Template, choose Blank, and click OK.

3.
Click Layout in the Design Tasks pane, as shown in Figure 8.10.

Figure 8.10. Design Tasks pane


4.
Select any layout, such as Table with Title. Now we will add a table and three controls.

5.
Click the task pane selector at the top of the Layout task pane and select Controls.

6.
Click Table in the top navigation and then Insert Layout Table.

7.
Create a simple two-column table with five rows by clicking Table Insert Layout Table and selecting 2 for Number of columns and 5 for Number of rows.

8.
Type text for the Assigned To and Comments fields in the cells.

9.
Merge the left and right columns in the third table row and drag it.

10.
Drag the Text Box control into the cells next to Assigned To and below Comments.

11.
Drag the Button control to one of the bottom cells, as shown in Figure 8.11.

Figure 8.11. Infopath form layout


12.
To name your controls, double-click on them to open the properties dialog box, as shown in Figure 8.12.

Figure 8.12. Text Box Properties


13.
To make the Comments text box a Multi-line text box, click the Display tab and check the Multi-line check box.

14.
Double-click the button to open the Button Properties dialog box to add logic to the OK button.

15.
Click the Rules button.

16.
Click the Add button and another Rule dialog box appears.

17.
Click the Add Action button, select Submit using a data connection from the Action pull-down menu, and then click the Add button to open the Data Connection Wizard. Accept the default selection to create a new connection for submitting data and click Next.

18.
Select To the hosting environment, such as an ASP.NET page or a hosting application and click Next.

19.
Give a descriptive name to your data connection and click Finish. Then click OK on the Action dialog box.

20.
Click Add Action again in the Rule dialog box.

21.
Select Close the form from the Action pull-down menu, uncheck the box for prompting the user, then click OK. Your dialog box should now look like Figure 8.13.

Figure 8.13. Rule dialog box with Submit and Close actions


22.
Click OK to close each of the remaining dialog boxes.

23.
You need to change some properties of your form to prepare it to work properly with SharePoint. Click Tools Form Options, and in the Form Options dialog box, click Security and Trust. In the left category list, uncheck Automatically determine security level. Select the Domain option as shown in Figure 8.14, and then click OK to close the dialog box.

Figure 8.14. Form options


24.
In the task pane, click Design Tasks and then click the Design Checker link.

25.
Click Change Compatibility Settings.

26.
In the Form Options dialog box, ensure that the Design a form template that can be opened in a browser or InfoPath check box is selected.

27.
Enter the URL of the SharePoint server on which you are deploying the workflow to verify that the form will work. Click OK and the connection progresses. If no errors are reported, you are in good shape to continue.

28.
Give your data a unique name. Click Design Tasks in the Task pane.

29.
Click Data Source. Your main data source is called myFields by default. Double-click myFields and change the Name to WikiInit. Click OK to save the changes.

30.
Save this form on your drive where you can easily open it again.

31.
Publish the InfoPath form by clicking File Publish, selecting the To a network location radio button, and then clicking Next.

32.
Click the Browse button, browse to where you created your VS 2005 workflow project, and pick the same directory as workflow1.cs. Name the file wikiInit.xsn. Now the wizard should look something like Figure 8.15

Figure 8.15. Publishing Wizard


33.
Click Next. Remove the alternate path to avoid problems with the form installation and click Next again. You will probably see the warning dialog box in Figure 8.16. After researching this message, it appears to be an issue that was known in the 2003 release and still has not been resolved. Simply click OK to continue publishing the form.

Figure 8.16. InfoPath security warning dialog box


34.
Click Publish and then click Close to close the wizard.

To have the data that is entered into the form passed to your workflow, you need to extract a class from the form and use it in your Visual Studio project.

35.
In the InfoPath form, click File Save As Source Files and save to a convenient location. Close the InfoPath application.

36.
Open a Visual Studio Command Prompt by clicking Start Microsoft Visual Studio 2005 Visual Studio Tools Visual Studio 2005 Command Prompt.

37.
Navigate to where you stored the source files, type dir, and press Enter to list the files. The screen should look like Figure 8.17.

Figure 8.17. Visual Studio Command Prompt


38.
Create a class out of the myschemea.xsd file to include in your Visual Studio solution. Type xsd myschema.xsd /c and press Enter. This creates a C# file at this location. Type dir to ensure that myschema.cs was created.

39.
To rename the myschema.cs file so that it maps to your solution, type rename myschema.cs wikiInit.cs.

40.
If the Wikiworkflow Visual Studio solution isn’t open, open it now. In the Solution Explorer pane, right-click Wikiworkflow and select Add Existing Item. Browse to your source files directory and add the wikiInit.cs file. Your command prompt window should be similar to Figure 8.18.

Figure 8.18. Wikiworkflow Solution – Visual Studio


Infopath form #2 creation

In these steps we will create the second InfoPath form and repeat some of the steps followed during the creation of form #1.

1.
You will now create Form #2. Open InfoPath. Select Design a Form Template, choose Blank, and click OK.

2.
Create a simple two-column table with five rows by clicking Table Insert Layout Table and selecting 2 for Number of columns and 5 for Number of rows.

3.
You need only three controls for this form: text box for comments, “complete” check box, and your Submit button. Type Comments in the first cell to label the field. Next, drag the text box for comments, check box, and button controls over.

4.
Rename the Comments control to Comments and the check box control to isComplete and the button to Submit using the procedures outlined previously. Now your form should look like Figure 8.19



Figure 8.19. Form #2


5.
Repeat steps 15 to 32 in this section again for this form. When you get to step 33, name the form wikiInit2.xsn so you do not overwrite the first form. Complete steps 34 to 37 and then begin again at step number 6.

6.
To pass the comment field from the initialization form to this form, you need to add a data source in which to pass the value. Open Notepad by clicking Start Run Notepad.

7.
Type <z:row xmlns:z=”#RowsetSchema” ows_comments=”” />, which should look like Figure 8.20. Be careful here not to copy and paste this row from Word because the quotes may change and cause an error when processing the XML code. You should just type this row into Notepad.

Figure 8.20. Notepad Text


8.
The ows_comments attribute corresponds with the Comments field in the form. You could associate other values in this file by preceding the InfoPath forms control names with ows_. Save this file as ItemMetadata.xml. Be sure the case is exactly the same as documented for the file name and save where you can easily retrieve it.

9.
Add this file to your InfoPath schema. Go back to InfoPath and in the task pane click Design Tasks Data Source Manage Data Connections.

10.
Click Add, and for Create a new connection to, select Receive data, as shown in Figure 8.21

Figure 8.21. Data Connection Wizard


11.
Click Next, select XML document, click Next, browse to the location of your ItemMetadata.xml file, select it, and then click Next. If you see an error here about expecting quotes, go back to step 51 and retype the quotes in Notepad. Word formats into something the code doesn’t recognize.

12.
Leave Include the data as a resource file in the form template or template part selected and click Next.

13.
Leave the name as ItemMetadata, select Automatically retrieve data when form is opened, and click Finish and then Close to get back to the form.

14.
You have to bind your comment control so the data is populated. Double-click the comments text box to open the properties window. Click the formula button beside the Default Value text box to open the Insert Formula dialog box. Click Insert Field or Group, and select the ItemMetadata data source from the drop-down box, as shown in Figure 8.22.



Figure 8.22. Select a Field or Group dialog box


15.
Select :ows_comments from the available fields (it should be the only one) and click OK.

16.
Click OK to close the Insert Formula dialog box, and click OK to close the Text Box Properties dialog box. Save the form and click File Publish to a network location as you did for the first form. Again, to make sure that you don’t have problems with the Access path, save it with a new name again even though you named it earlier. Save the form this time with the name ModerateWiki.xsn and click Next.

17.
Delete the Access Path and then click Next again.

18.
Click OK to continue publishing the template, click Publish, and then Close.

19.
Close InfoPath to begin the Visual Studio Section.

Visual Studio Code Authoring/Programming

After all of those steps, it may be valuable to walk through the workflow logic again.

Visual Studio should still be opened to your project. If not, open the project you created earlier. You already have the onWorkflowActivated1 control in the Visual Studio Designer. To view the code behind the workflow, right-click the Workflow1.cs [Design] page and choose View Code. You will see the screen in Figure 8.23.

Figure 8.23. Workflow code


1.
Go back to the Designer and double-click the onWorkflowActivated1 control, which generates the onWorkflowActivivated1_Invoked event handler in the code and will open it for editing.

2.
If the toolbox is not already visible on-screen, click View and then Toolbox. Right-click in the toolbox and select Choose Items.

3.
On the Choose Toolbox Items dialog box, reorder the items according to namespace and find the items with the namespace Microsoft.Sharepoint.WorkflowActions. (You may also use the filter and type Sharepoint.workflow.) Select them all, as in Figure 8.24, and click OK.

Figure 8.24. Toolbox Items


Note

If you don’t see the items listed in the toolbox, be sure that you have clicked the Design page because those controls are context sensitive.

4.
Close the toolbox for now by clicking the X in the upper right corner. Click the onWorkflowActivated1 control. The Properties pane shows the properties of this workflow step. You don’t have to change anything in the properties, but you should note the properties that are available to you. Notice the CorrelationToken, and expand the WorkflowProperties item and notice the two child properties: Name and Path. The workflowProperties that the path is associated with are the same as in this section of code:

public
Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties
   workflowProperties =
      new
Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();

5.
Drag on the first activitiy. Find CreateTask in the toolbox and drag it on to the designer. Place it directly under the onWorkflowActivated1 activity.

6.
Double-click the createTask1 control to create the code to handle that event. Go back to the Designer tab. There are a few properties that need to be set at this point. Make sure that the focus is on the createTask1 control, and have a look at the Properties pane as shown in Figure 8.25.

Figure 8.25. The createTask Properties pane


7.
Place your cursor into the field next to the CorrelationToken property. Type taskToken.

8.
Expand CorrelationToken by clicking the plus sign, click OwnerActivityName, and set Workflow1 as the activity name.

There are two ways to bind your tasked and task properties. You can do it via code, or you can allow Visual studio to bind them. Let’s do it both ways starting with code.

9.
Add the line:

public Guid taskId = default(System.Guid);

into the code, anywhere outside of any method is fine. Your code should now look like this:

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Xml.Serialization;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.Office.Workflow.Utility;
namespace WikiWorkflow
{
  public sealed partial class Workflow1:
SequentialWorkflowActivity
  {
          public Workflow1()
          {
                 InitializeComponent();
          }

    public Guid taskId = default(System.Guid);
    public Guid workflowId = default(System.Guid);
    public SPWorkflowActivationProperties workflowProperties =
      new SPWorkflowActivationProperties();
    private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
    {

    }

    private void createTask1_MethodInvoking(object sender, EventArgs e)
    {

    }


  }

}

You don’t need all of the using statements, so feel free to refactor to get rid of the unused ones at any time.

10.
Back in the designer, you can now bind to the taskId. Click the TaskId property on the Properties pane for createTask1, and then click the ellipse that appears (...). This opens the binding dialog box. Select taskId as shown in Figure 8.26.

Figure 8.26. Bind TaskId to an activity’s property.


11.
Click OK. In the Properties pane, expand the TaskId node. You will notice that the path is now set to taskId.

12.
The other method of binding is to let Visual Studio handle the work. We will use this method to bind the TaskProperties node. Click the TaskProperties property and then click the ellipse to open the binding dialog box. This time, click the “Bind to a new member” tab.

13.
Click the Create Field radio button and change the member name to taskProps, as shown in Figure 8.27, and click OK.

Figure 8.27. Bind TaskProperties to an activity’s property


14.
Expand the TaskProperties node and notice that the path is now set to taskProps. Go to the code view and notice that the following line was added to the code:

public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties
   taskProps = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

15.
Now you need to loop and wait until the task is set to complete. Go back to the Design tab and Find the While control in the toolbox under the Windows Workflow category. Drag it under the createTask1 activity.

16.
In the Conditions property, choose Code Condition from the pull-down menu. Expand the node, and beside Condition type notFinished and press Enter. The notFinished method is generated in the code.

17.
Add an activity into the while loop to tell the loop when to break and move forward. Find the OnTaskChanged control and drop it into the while loop.

18.
Set the CorrelationToken property to taskToken. Bind the TaskId to the existing taskId and bind the BeforeProperties and AfterProperties to new members, leaving the radio button on the default of Create Property for both. Your list of existing properties now looks like Figure 8.28.

Figure 8.28. Before and After Properties


19.
Click OK. In the Properties pane, under Handlers, click Invoked, type onTaskChanged, and press Enter to generate the onTaskChanged method in the code.

20.
Add the last item to the designer. Find CompleteTask in the toolbox and drop it under the While activity. Bind the CorrelationToken property to taskToken, the TaskId to the existing taskId, and double-click the completeTask1 control you just dragged onto the form to create the event handler in the code. Your designer should now look like Figure 8.29.



Figure 8.29. Working with the Designer


Your code, without all of the using statements at the top, should look like:

namespace Wikiworkflow
{
      public sealed partial class Workflow1:
SequentialWorkflowActivity
       {
              public Workflow1()
               {
                InitializeComponent();
              }

    public Guid taskId = default(System.Guid);
    public Guid workflowId = default(System.Guid);
    public
Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties
workflowProperties = new
Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();
    private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
    {

    }

    private void createTask1_MethodInvoking(object sender, EventArgs e)
    {

    }

    public
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties
taskProps = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

    private void notFinished(object sender, ConditionalEventArgs e)
    {

    }

    public static DependencyProperty afterPropsProperty =
DependencyProperty.Register("afterProps",
typeof(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties),
typeof(Wikiworkflow.Workflow1));

[DesignerSerializationVisibilityAttribute(DesignerSerialization
Visibility.Visible)]
[BrowsableAttribute(true)]
[CategoryAttribute("Misc")]
    public
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties
afterProps
    {
      get
{
return
((Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)(base.
GetValue(Wikiworkflow.Workflow1.afterPropsProperty)));
}
      set
{
base.SetValue(Wikiworkflow.Workflow1.afterPropsProperty, value);
}
    }
    public static DependencyProperty beforePropsProperty =
DependencyProperty.Register("beforeProps",
typeof(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties),
typeof(Wikiworkflow.Workflow1));

[DesignerSerializationVisibilityAttribute(DesignerSerialization
Visibility.Visible)]
[BrowsableAttribute(true)]
[CategoryAttribute("Misc")]
    public
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties
beforeProps
    {
      get
{
return
((Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)(base.
GetValue(Wikiworkflow.Workflow1.beforePropsProperty)));
}
      set
{
base.SetValue(Wikiworkflow.Workflow1.beforePropsProperty, value);
}
    }

    private void onTaskChanged(object sender, ExternalDataEventArgs e)
    {

    }

    private void completeTask1_MethodInvoking(object sender, EventArgs e)
    {

    }


    }
       }

}

21.
Find the onWorkflowActivated1_Invoked method, and just above it, declare some properties:

private string assignee = default(String);
private string comments = default(String);

22.
These should look familiar. They represent the InfoPath controls you added to your first form. You need to set these properties with the data passed into the workflow in the workflowProperties code. In order to access the workflow properties though, you need to parse the XML string passed in. This is where you use the WikiInit.cs file you added to the solution.

Inside the onWorkflowActivated1_Invoked method, add the following code between the brackets:

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
       workflowId = workflowProperties.WorkflowId;

    XmlSerializer serializer = new
XmlSerializer(typeof(WikiInit));
    XmlTextReader reader = new XmlTextReader(new
System.IO.StringReader(workflowProperties.InitiationData));
    WikiInit wikiInit =
(WikiInit)serializer.Deserialize(reader);

    assignee = wikiInit.Assignee;
    comments = wikiInit.Comments;

}

Basically what you are doing is reading in the data passed in from the first InfoPath form into our workflow when the workflow is initialized.

23.
The createTask1_MethodInvoking method is called just before the task is actually created, so you should set some properties on the task here, by adding the code between the brackets below:

private void createTask1_MethodInvoking(object sender, EventArgs e)
    {
      taskId = Guid.NewGuid();
      taskProps.Title = "Moderate Wiki please.";
      taskProps.AssignedTo = assignee;
      taskProps.Description = comments;
      taskProps.ExtendedProperties["comments"] = comments;

      // just for fun, lets add the wiki content to the email
thats going out to the
      // assignee - note - this will only work for wiki items
      SPListItem item = workflowProperties.Item;
      if (item["Wiki Content"] != null)
        taskProps.EmailBody += item["Wiki Content"];

    }

24.
Now we have come to the while loop. Recall in the second InfoPath form, you added a check box called isComplete. You have to add that corresponding flag to your code, so directly above the notFinished method add:

private bool isComplete;

25.
Your while loop calls the notFinished method and loops until the event passed into the notFinished method is set to false. Add the code between the brackets below to the notFinished method.

private void notFinished(object sender, ConditionalEventArgs e)
 {
   e.Result = !isComplete;
 }

26.
Check the check box state in the afterProperties node in the onTaskChanged method and set the isComplete boolean equal to this condition. Add the code between the brackets to the method.

private void onTaskChanged(object sender, ExternalDataEventArgs e)
    {
      isComplete =
bool.Parse(afterProps.ExtendedProperties["isComplete"].ToString
());
    }

27.
Click Build Build Workflow in the top navigation to build your solution.

Hopefully, you will not have errors and you can move on to the Deploying and Debugging activities.

Deploying and debugging

This section details the deployment and debugging of the example and we can enjoy the fruit of our hard labor.

1.
First, you need to sign your assembly. In the Solutions Explorer window, right-click your project file in Visual Studio and select Properties.

2.
Check the “Sign the assembly” box and in the Choose a strong name key file field select <New...> from the pull-down menu. This opens a Create a strong Name Key dialog box. Enter a name—we use sn when building samples—and uncheck protect my key with a password as shown in Figure 8.30.

Figure 8.30. Create Strong Name Key dialog box


3.
Click OK and then rebuild your project. The assembly is now strongly named and you must add it to the GAC (Global Assembly Cache).

4.
Open the GAC located in your C:/WINDOWS/assembly directory in one window, and in another window browse to your project, then to the /bin/debug folder. Your assembly should be named WikiWorkflow.dll if you followed my naming conventions. Drag and drop your DLL into the GAC window. Leave the GAC open for now; you’ll have to get some data from it in a minute.

5.
Go back to Visual Studio. Some files were created by default and are critical to deploying your workflow. In the Solutions Explorer window, find the feature.xml file and double-click to open. It is mostly blank. Add the code snippet by following the instructions in the file. Your screen should now be similar to Figure 8.31.

Figure 8.31. Feature XML code


6.
You need to change a few things before you can save this. First, you need a globally unique identifier (GUID). In a Visual Studio Command Prompt, run the guidgen.exe command. If you don’t have the GUID Generator tool, you can get it from www.microsoft.com/downloads/details.aspx?FamilyID=94551F58-484F-4A8C-BB39-ADB270833AFC&displaylang=en. If you download it to the C:Program Files Microsoft Visual Studio 8 directory and then run it, the .exe will prompt you to choose a directory for the extracted files, as shown in Figure 8.32.

Figure 8.32. Guidgen.exe


7.
Launch guidgen.exe, generate a GUID using the Registry Format, and paste it into the Id attribute, without the braces. Give your workflow a title and a description and the rest can be left as is. Your code should look like the following:

<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="1033" _version="12.0.3111" _dal="1" -->
<!-- _LocalBinding -->

<!-- Insert Feature.xml Code Snippet here.  To do this:
1) Right click on this page and select "Insert Snippet" (or
press Ctrl+K, then X)
2) Select Snippets->SharePoint Server Workflow->Feature.xml
Code -->
<Feature  Id="96DA466C-F4E9-4bd3-A4E9-26C3E993BED8"
           Title="Wiki Workflow"
           Description="This feature is a workflow that assigns
a user to moderate a wiki."
           Version="12.0.0.0"
           Scope="Site"
           ReceiverAssembly="Microsoft.Office.Workflow.Feature,
Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"

ReceiverClass="Microsoft.Office.Workflow.Feature.WorkflowFeatur
eReceiver"
           xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
         <ElementManifest Location="workflow.xml" />
  </ElementManifests>
  <Properties>
         <Property Key="GloballyAvailable" Value="true" />

         <!-- Value for RegisterForms key indicates the path to
the forms relative to feature file location -->
         <!-- if you don't have forms, use *.xsn -->
         <Property Key="RegisterForms" Value="*.xsn" />
  </Properties>
</Feature>

8.
Open the workflow.xml file and insert the snippet code. Create another GUID for the Id attribute. Insert a title and description, and for the CodeBesideClass attribute, use the namespace and class name of your workflow. In this example, it is WikiWorkflow.Workflow1.

9.
Go back to the GAC, right-click the assembly you added, and copy and paste the public key token into the CodeBesideAssembly PublicKeyToken attribute. The other attributes can be left as they are.

10.
In your project directory, find your published forms—not the templates you designed, but the forms you published. Right-click WikiInit.xsn and open it in Design mode. Click File Properties and copy and paste the ID into the Association_FormURN and Instantiation_FormURN nodes. Do the same for ModerateWiki.xsn and paste that ID into Task0_FormURN. You can remove the Modification_GUID_FormURN and Modification_GUID_Name nodes. Your workflow.xml file should look like this:

<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.3015" _dal="1"  -->
<!-- _LocalBinding  -->
<!-- Insert Workflow.xml Code Snippet here. To do this:
1) Right click on this page and select "Insert Snippet" (or
press Ctrl+K, then X)
2) Select Snippets->SharePoint Server Workflow->Workflow.xml
Code -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Workflow
               Name="WikiWorkflow"
               Description="Cool Wikiworkflow"
               Id="BAE96906-8C1B-4671-BBB0-FF8E9EA14D70"
               CodeBesideClass="WikiWorkflow.Workflow1"
               CodeBesideAssembly="WikiWorkflow,
Version=3.0.0.0, Culture=neutral,
PublicKeyToken=594c21e3c620f598"

TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F931
60"
               AssociationUrl="_layouts/CstWrkflIP.aspx"
               InstantiationUrl="_layouts/IniWrkflIP.aspx"
               ModificationUrl="_layouts/ModWrkflIP.aspx">

               <Categories/>
               <!-- Tags to specify InfoPath forms for the
workflow; delete tags for forms that you do not have -->
               <MetaData>
                    <Association_FormURN>urn:schemas-microsoft-
com:office:infopath:wikiInit:-myXSD-
2006-12-26T17-55-26</Association_FormURN>
                     <Instantiation_FormURN>urn:schemas-
microsoft-com:office:infopath:wikiInit:-myXSD-
2006-12-26T17-55-26</Instantiation_FormURN>
                     <Task0_FormURN>urn:schemas-microsoft-
com:office:infopath:ModerateWiki:-myXSD-
2006-12-31T19-02-43</Task0_FormURN>


     <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
              </MetaData>
    </Workflow>
</Elements>

11.
Now open the install.bat file. Follow the instructions at the top of the file, and you should end up with something like:

:: Before running this file, sign the assembly in Project
properties
::
:: To customize this file, find and replace
:: a) "MyFeature" with your own feature name
:: b) "[IP_FORM_FILENAME]" with InfoPath form that needs to be
uploaded (add additional lines for multiple forms)
:: b) "feature.xml" with the name of your feature.xml file
:: c) "workflow.xml" with the name of your workflow.xml file
:: d) "http://localhost" with the name of the site you wish to
publish to

echo Copying the feature...

rd /s /q "%CommonProgramFiles%Microsoft Sharedweb server
extensions12TEMPLATEFEATURESWikiWorkflow"
mkdir "%CommonProgramFiles%Microsoft Sharedweb server
extensions12TEMPLATEFEATURESWikiWorkflow"

copy /Y feature.xml "%CommonProgramFiles%Microsoft Sharedweb
server extensions12TEMPLATEFEATURESWikiWorkflow"
copy /Y workflow.xml "%CommonProgramFiles%Microsoft Sharedweb
server extensions12TEMPLATEFEATURESWikiWorkflow"
xcopy /s /Y *.xsn "%programfiles%Common FilesMicrosoft
Sharedweb server
extensions12TEMPLATEFEATURESWikiWorkflow"



echo Adding assemblies to the GAC...

"%programfiles%Microsoft Visual Studio
8SDKv2.0Bingacutil.exe" -uf WikiWorkflow
"%programfiles%Microsoft Visual Studio
8SDKv2.0Bingacutil.exe" -if binDebugWikiWorkflow.dll

:: Note: 64-bit alternative to lines above; uncomment these to
install on a 64-bit machine
::"%programfiles% (x86)Microsoft Visual Studio
8SDKv2.0Bingacutil.exe" -uf WikiWorkflow
::"%programfiles% (x86)Microsoft Visual Studio
8SDKv2.0Bingacutil.exe" -if binDebugWikiWorkflow.dll



echo Verifying InfoPath Forms...

::Note: Verify InfoPath forms; copy line for each form
"%programfiles%common filesmicrosoft sharedweb server
extensions12instsadm" -o verifyformtemplate -filename
WikiInit.xsn
"%programfiles%common filesmicrosoft sharedweb server
extensions12instsadm" -o verifyformtemplate -filename
ModerateWiki.xsn
echo Activating the feature...

pushd %programfiles%common filesmicrosoft sharedweb server
extensions12in

::Note: Uncomment these lines if you've modified your
deployment xml files or IP forms
::stsadm -o deactivatefeature -filename
WikiWorkflowfeature.xml -url http://mossdev.avitivacorp.com
::stsadm -o uninstallfeature -filename WikiWorkflowfeature.xml

stsadm -o installfeature -filename WikiWorkflowfeature.xml -
force
stsadm -o activatefeature -filename WikiWorkflowfeature.xml -
url http://mossdev.avitivacorp.com

echo Doing an iisreset...

popd
iisreset

12.
Open a command prompt and navigate to your project directory. Type install and watch to be sure no errors are reported. You have installed the workflow! Now you can test it.

13.
Go to your Wiki site and to the Wiki pages document library, which will be a URL similar to http://mossdev/WF%20Wiki/Forms/AllPages.aspx.

14.
Choose Settings Document Library Settings Workflow settings. Choose Wiki workflow from the workflow list, and give it a unique name.

15.
Select a new task list and a new history list, and select Allow this workflow to be manually started by an authenticated user with Edit Items Permissions, Start this workflow when a new item is created, and Start this workflow when an item is changed. Click Next. Surprise, there’s your first form!

16.
Fill out this form with some valid data. Use a name that you know will resolve with a valid user e-mail address. Click OK.

17.
To debug, go back to Visual Studio and click Debug Attach to Process. Find w3wp.exe in the list and click Attach.

18.
Give Visual Studio a few seconds before proceeding. Go to the Workflow1.cs code and put a breakpoint on the first line of all four of your methods. The process will now stop at these breakpoints and you can see the values that are passed in.

19.
Go back to the Wiki site. Open one of the Wiki pages and click Edit. Wrap a few words in [[ ]] tags so SharePoint knows to create a Wiki page. Click OK, and Visual Studio should grab that process because you set it to start on edit of a page.

20.
The line is yellow where the debug process has stopped, and you can step through by pressing F10. You can run through to the next breakpoint by pressing F5, but I suggest stepping through. Mousing over the variables should give you a popup of the values they hold.

21.
Go check out the task list that was created, and you should see a new task assigned to the assignee you specified, with the title Moderate Workflow please. Open this task and you’ll see form #2.

22.
Add some more comments and click Save. Don’t set as complete yet. Step through Visual Studio. You will notice that OnTaskChanged was called, but not the initialize method or the create task method. Open the task again, and you’ll see that your comments were saved. This time, check Complete and click OK. The workflow is complete, nice work!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.111.134