Share via


How to: Implement a SharePoint Workflow with ASP.NET Forms

SharePoint workflows use forms to handle interactions with users. SharePoint provides two approaches for implementing custom workflow association and initiation forms, modification forms, status forms, and task forms. One approach, which can be used with any Windows SharePoint Services 3.0 installation, uses ASP.NET forms. The other approach, which is only available with Microsoft Office SharePoint Server 2007, uses InfoPath forms. This topic discusses the first approach.

The following procedure is a high-level description of how to use Visual Studio to create ASP.NET custom workflow task forms. This procedure assumes that you can structure a solution in Visual Studio that can deploy a content type, a custom ASPX page, and a workflow. You can use Visual Studio extensions for Windows SharePoint Services and the Visual Studio workflow project template to help you develop and deploy these items.

To create ASP.NET workflow task forms

  1. Using Visual Studio extensions for Windows SharePoint Services, create a custom content type for workflow tasks that is derived from the Workflow Task content type (0x010801). It must specify the URL of the form that displays the task. The following code is an example of a custom workflow task content type.

    <ContentType ID="0x01080100b3629edc2920465085800d1eb262d5ad"
                   Name="My Workflow Task"
                   Group="My Group"
                   Description="My Workflow Task Content Type"
                   Version="0">
        <FieldRefs/>
        <XmlDocuments>
          <XmlDocument
    NamespaceURI="https://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url
                                                                                ">
            <FormsUrl  xmlns="https://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
              <Display>_layouts/MyTaskForm.aspx</Display>
            </FormsUrl>
          </XmlDocument>
        </XmlDocuments>
    </ContentType>
    
  2. Associate the workflow with the custom workflow task content type. Use the TaskListContentTypeID attribute to do this. The following code shows an example.

    <Workflow
         Name="My Workflow"
         Description="Workflow that handles my business process."
         Id="d2eca905-b799-4ec2-aed6-783ee46337ad"
      CodeBesideClass="MyWorkflowAssembly.MyWorkflowClass"
         CodeBesideAssembly="MyWorkflowAssembly, Version=1.0.0.0, Culture=neutral,
                                                  PublicKeyToken=9f4da00116c38ec5" 
         TaskListContentTypeId="0x01080100b3629edc2920465085800d1eb262d5ad">
        <Categories/>
        <MetaData>     
          <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
        </MetaData>
    </Workflow>
    
  3. In Visual Studio, create a new ASP.NET Web form that can be deployed to a SharePoint site with a feature. One method for creating this form is to copy one of the list forms that Visual Studio extensions for Windows SharePoint Services provides from the list definition project template. This file is already populated with content elements from the SharePoint master page. Copy the file and reference a custom code behind file that replaces the SharePoint code behind reference. To deploy the form to the _layouts virtual directory, do the following:

    1. In your Visual Studio extensions for Windows SharePoint Services project, create a folder named Templates.
    2. Inside the Templates folder, create a folder named Layouts.
    3. Inside the Layouts folder, add the Web form. The Web solution package that Visual Studio extensions for Windows SharePoint Services creates will then deploy the form to the _layouts virtual directory.
  4. Write the ASP.NET Web form code behind. It should derive from the Microsoft.SharePoint.WebControls.LayoutsPageBase class. The code should both process the workflow task and allow the user to perform the desired action for the task. The workflow task provides the data in a query string that can be used by the custom ASP.NET Web form. The following code shows an example of data that is provided by the query string.

    Request.QueryString["List"]; //the Guid Id of the workflow task list
    Request.QueryString["ID"]; //the List Item Id of the workflow task
    Request.QueryString["Source"]; //the URL of the referrer page
    

The following is more information about creating workflow forms:

Home page on MSDN | Community site