为SharePoint 2010 Workflow 开发 Custom(自定义的) Workflow Activity

为SharePoint 2010 Workflow 开发 Custom Workflow Activity(Develop Custom Workflow Activity for SharePoint 2010 Workflow).

 SharePoint2010提供了很多有用的开箱即用的Activity(活动action),我们可以在SharePoint Designer 2010 中看到这些自带的操作(actions).

但有时当这些需求不能满足我的需求,但是我又想用开箱即用的Activity(活动action)来设计工作流,这时我们就需要开发自己的Workflow Activity(action).

本文将介绍如何开发一个自定义的Workflow Activity(action),并在SharePoint Designer 2010 使用该自定义的Workflow Activity。

1. File ---> New Project-----> Visual C# ---> SharePoint | 2010 ----> Empty Project

点击"Finish"

2. 选中刚刚建的解决方案,左击,Add->New Project->Visual C#->WorkFlow

点击OK

 

3. 在项目CreateActivityDemo中添加CreateSurveyList.cs (activity)

4.在项目CreateActivityDemo中添加以下引用

  a. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll

   b. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\microsoft.sharepoint.WorkflowActions.dll

 

5. 在CreateSurveyList.cs 中添加如下命名空间

[csharp]  view plain copy
  1. using Microsoft.SharePoint;  
  2. using Microsoft.SharePoint.Workflow;  
  3. using Microsoft.SharePoint.WorkflowActions;  
[csharp]  view plain copy
  1.    

6. 在CreateSurveyList.cs中添加SiteUrlProperty ,用于存储SiteUrl,这个属性可以在SharePoint 2010 Designer 看到,我们可以设置它

[csharp]  view plain copy
  1. public static DependencyProperty SiteUrlProperty = DependencyProperty.Register("SiteUrl",typeof(string), typeof(CreateSurveyList), new PropertyMetadata(""));  
  2.         [DescriptionAttribute("Url of site where survey is to be created")]  
  3.         [BrowsableAttribute(true)]  
  4.         [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]  
  5.         [ValidationOption(ValidationOption.Required)]  
  6.         public string SiteUrl { get { return ((string)(base.GetValue(CreateSurveyList.SiteUrlProperty))); } set { base.SetValue(CreateSurveyList.SiteUrlProperty, value); } }  

 

7. 在CreateSurveyList.cs中添加SurveyListNameProperty

[csharp]  view plain copy
  1. public static DependencyProperty SurveyListNameProperty = DependencyProperty.Register("SurveyListName",typeof(string), typeof(CreateSurveyList), new PropertyMetadata(""));  
  2.        [DescriptionAttribute("Name for survey list")]  
  3.        [BrowsableAttribute(true)]  
  4.        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]  
  5.        [ValidationOption(ValidationOption.Required)]  
  6.        public string SurveyListName { get { return ((string)(base.GetValue(CreateSurveyList.SurveyListNameProperty))); } set { base.SetValue(CreateSurveyList.SurveyListNameProperty, value); } }  


8. 在CreateSurveyList.cs添加以下代码,用于覆盖Activity的运行方法

[csharp]  view plain copy
  1. protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)   
  2.        {   
  3.            this.CreateSurveyLibrary();   
  4.            return ActivityExecutionStatus.Closed;  
  5.        }         
  6.          
  7.        private void CreateSurveyLibrary()   
  8.        {   
  9.            using (SPSite oSPSite = new SPSite(SiteUrl))  
  10.            {   
  11.                using (SPWeb oSPWeb = oSPSite.RootWeb)  
  12.                {  
  13.                    Guid ID = oSPWeb.Lists.Add(SurveyListName, SurveyListName + System.DateTime.Now.ToString(), SPListTemplateType.Survey);   
  14.                    SPList oSPList = oSPWeb.Lists[ID]; oSPList.OnQuickLaunch = true; oSPList.Update();   
  15.                }  
  16.            }   
  17.        }  
[csharp]  view plain copy
  1.    

9.为项目CreateActivityDemo添加强名


编译CreateActivityDemo,显示编译成功

 

10.  右击CustomWorkflowActivityDemo 先择Add ---> SharePoint Mapped Folder,定位到Template->1033->Workflow

11. 在刚刚添加的WorkFlow文件夹中添加CreateActivityDemo.Actions,一个xml 文件,后缀名Actions会被SharePoint Desginer 2010识别

[html]  view plain copy
  1. <WorkflowInfo>  
  2.   <Actions Sequential="then" Parallel="and">  
  3.     <Action Name="Create Survey List"  
  4.         ClassName="CreateActivityDemo.CreateSurveyList"  
  5.         Assembly="CreateActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=331ffcc01b13c340"  
  6.         AppliesTo="all"  
  7.         Category="Sundar Activity">  
  8.       <RuleDesigner Sentence="Survey List Name %1 to site %2.">  
  9.         <FieldBind Field="SurveyListName" Text="Survey List Name"  
  10.            DesignerType="TextArea" Id="1"/>  
  11.         <FieldBind Field="SiteUrl" Text="Url of base site" Id="2"  
  12.            DesignerType="TextArea"/>  
  13.       </RuleDesigner>  
  14.       <Parameters>  
  15.         <Parameter Name="SurveyListName" Type="System.String, mscorlib"  
  16.       Direction="In" />  
  17.         <Parameter Name="SiteUrl" Type="System.String, mscorlib"  
  18.       Direction="In" />  
  19.       </Parameters>  
  20.     </Action>  
  21.   </Actions>  
  22. </WorkflowInfo>  

注意PublicKeyToken=331ffcc01b13c340是需要替换的,不同的项目不一样,具体可以用Reflector查看


12. 双击CustomWorkFlowActivityDemo 中的Package.Package,点击Advanced, 添加Safe Control ‘CreateActivityDemo’

13.在C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config中添加(在<authorizedTypes>节点下

[html]  view plain copy
  1. <authorizedType Assembly="CreateActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=331ffcc01b13c340" Namespace="CreateActivityDemo" TypeName="*" Authorized="True" />  

注意PublicKeyToken=331ffcc01b13c340是需要替换的,不同的项目不一样

 

14.部署CustomWorkFlowActivityDemo (不出意外部署应该是成功的)

15.启动Microsoft SharePoint Designer 2010,打开网站http://ccpc/ ,选择工作流,新建工作流(基于某个List,例如我的是Agents),工作流启动条件为新建项目

16. 添加我们开发好的activty,并保存和发布工作流

 

18.查看工作流建好的Survery

至此开发自定义的Moss 2010 action(activity)完成了,希望本文对朋友们有帮助。

 

需要的朋友可以从这里下载到该实例的代码:http://download.csdn.net/source/3573107

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值