Introduction

This blog is mainly focused on SharePoint
I will use this to store and share all the tips and tricks about SharePoint and the related products
List of all posts

SharePoint 2010: Create a Custom Worflow Activity with Visual Studio Part 2


Create a Custom Worflow Activity with Visual Studio Part 1

Step Description
1In visual studio 2010, add a new project to your solution.
2Choose Empty SharePoint 2010 Project
3Configure the SharePoint Server
4aAdd a SharePoint Mapped Folder to your solution
4bBrowse to TEMPLATE/Workflow
5aAdd a new item to the mapped folder
5bSelect XML file and name it tztools.ACTIONS
5cAdd information based on your activity
<?xml version="1.0" encoding="utf-8" ?>
<WorkflowInfo>
  <Actions Sequential="then" Parallel="and">
    <Action Name="RegEx evaluation"
            ClassName="tztools.tzRegEx"
            Assembly="tztools, Version=1.0.0.0, Culture=neutral, PublicKeyToken=887d18a96eeddf51"
            AppliesTo="List" Category="TzTools">
      <RuleDesigner Sentence="Parse %1 using %2 and set result in %3">
        <FieldBind Field="xListItemField" Text="field" Id="1" DesignerType="WritableFieldNames" />
        <FieldBind Field="xRegEx" Text="Regular Expression" Id="2" DesignerType="" />
        <FieldBind Field="xResult" Text="Parsing Result" Id="3" DesignerType="ParameterNames" />
      </RuleDesigner>
      <Parameters>
        <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In" DesignerType="Hide" />
        <Parameter Name="__ListId" Type="System.String, mscorlib" Direction="In"  DesignerType="Hide" />
        <Parameter Name="__ListItem" Type="System.Int32, mscorlib" Direction="In" DesignerType="Hide" />
        <Parameter Name="xListItemField" Type="System.String, mscorlib" Direction="In" DesignerType="WritableFieldNames" Description="Field to get the value of" />
        <Parameter Name="xResult" Type="System.String, mscorlib" Direction="Out" />
        <Parameter Name="xRegEx" Type="System.String, mscorlib" Direction="In" />
      </Parameters>
    </Action>
  </Actions>
</WorkflowInfo>
6aAdd en event receiver to your feature
6bAdd the following code :
(in the using section
using Microsoft.SharePoint.Administration;
and in the code part
public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webapp = (SPWebApplication)properties.Feature.Parent;
            SPWebConfigModification modAuthorizedType = new SPWebConfigModification();
            modAuthorizedType.Name = "AuthType";
            modAuthorizedType.Owner = "tztools";
            modAuthorizedType.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes";
            modAuthorizedType.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            modAuthorizedType.Value = "";
            webapp.WebConfigModifications.Add(modAuthorizedType);
            webapp.WebService.ApplyWebConfigModifications();
        }
7aNow we want to add the tztools to our package. Dubble click on package.package
7bClick on Advanced
7cFrom the new form,select Add -> Add Assembly from project output
7dAdd the output dll from the tztools project
8Build and deploy, your activity is now available in SharePoint Designer

No comments:

Post a Comment

by Category