快捷搜索:

VS2012开发SharePoint 2013客户化的action实例

本文讲述应用VS2012 开拓SharePoint 2013 客户化的action (代码)。

应用代码 客户化的action的action好处是所有本地代码可以做的工作都可以做,相对声明式的action 更机动和强大年夜,然则Office 365和SharePoint online是不支持的,只能支配在on-promise 情况。

下面以一个简单需求为例来讲述若何应用代码开拓SharePoint 2013 客户化的action:

需求:开拓一个action反转一个字符,输入要反转的字符串,输出反转结果

筹备事情同:http://www.fengfly.com/plus/view-214362-1.html

应用VS 2012完成以下事情:

1. 新建一个Workflow library 的项目,命名为CustomCodeActions

2. 在项目中新建 code activity Item

3. ReverseString.cs 内容为:

using System;

using System.Collections.Generic;using System.Linq;

using System.Text;using System.Activities;

namespace CustomCodeActions

{public sealed class ReverseSretring : CodeActivity

{// Define an activity input argument of type string

[RequiredArgument]

public InArgumentstring> Input { get; set; }//输入参数

[RequiredArgument]public OutArgumentstring> Output { get; set; } // 输出参数

// If your activity returns a value, derive from CodeActivity

// and return the value from the Execute method.protected override void Execute(CodeActivityContext context)

{string input = Input.Getstring>(context);//取得输入参数

char[] arr = input.ToCharArray();Array.Reverse(arr);

string output = new string(arr);Output.Set(context, output);// 设置输出参数

}}

}

4. 新建 AllowedTypes.xml,内容为:

xml version="1.0" encoding="utf-8" ?>

AllowedTypes>Assembly Name="CustomCodeActions">

Namespace Name="CustomCodeActions">Type>ReverseSretringType>

Namespace>Assembly>

AllowedTypes>

该文件支配时要复制到

%ProgramFiles%Workflow Manager1.0WorkflowArtifacts

%ProgramFiles%Workflow Manager1.0WorkflowWFWebRootbin

5. 给项目添加强名

6.编译项目,应用VS2012 Command Prompt运行如下敕令取PublickeyToken,第7步会用到它

sn -T CustomCodeActions.dll

7. 新建 ReverseString.actions4,内容为(留意调换PublickeyToken)

xml version="1.0" encoding="utf-8"?>

WorkflowInfo Language="en-us">Actions>

ActionName="ReverseSretring"

ClassName="CustomCodeActions.ReverseSretring"Assembly ="CustomCodeActions, Version=1.0.0.0, Culture=neutral, PublickeyToken=e99e4e028044a473"

Category="Custom"AppliesTo="all">

RuleDesigner Sentence="Reverse string %1 and out put to %2">

FieldBind Field="Input" Text="Input string" Id="1" DesignerType="TextOnly" DisplayName="Input string" />FieldBind Field="Output" Text="Output string" Id="2" DesignerType="ParameterNames" DisplayName="Output string" />

RuleDesigner>Parameters>

Parameter Name="Input" Type="System.String, mscorlib" Direction="In" DesignerType="TextOnly" Description="Input string" />Parameter Name="Output" Type="System.String, mscorlib" Direction="Out" DesignerType="ParameterNames" Description="Output string" />

Parameters>Action>

Actions> WorkflowInfo>

支配code action:

1.在Workflow manager box上的支配

a.将CustomCodeActions.dll 和AllowedTypes.xml拷贝到如下目录

%ProgramFiles%WorkflowManager1.0WorkflowArtifacts

%ProgramFiles%WorkflowManager1.0WorkflowWFWebRootbin

b.重启"Workflow Manager backend"办事

2. 在SharePoint box办事器上的支配

a. 将 CustomCodeActions.dll注册到GAC (应用 gacutil/iCustomCodeActions.dll)

b. 将ReverseString.actions4拷贝到 ~ProgramFilesCommon Filesmicrosoft sharedWeb ServerExtensions15TEMPLATE1033Workflow

c. 重启IIS

测试CodeAction

1. 清空SharePoint designer 2013 的缓存 C:Usersv-abchenAppDataLocalMicrosoftWebsiteCache

2. 启动SharePoint designer 2013,新建一个基于SharePoint 2013 平台的Site workflow

3. 给worklfow添加两个string变量

4. 将messageNeedReverse设置为123456789,并添加ReverString action

5. 输入变量设置为messageNeedReverse,输出变量设置为reversedMessage,将reversedMessage记录到workflow history 中,并添加go to "End of workflow" 停止事情流的语句

6. 启动测试事情流(不要应用系统帐号启动),等待其完成,查看workflow history:

您可能还会对下面的文章感兴趣: