您的位置:首页 > 其它

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

2015-03-24 08:54 696 查看
为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
plaincopy

using Microsoft.SharePoint;  

using Microsoft.SharePoint.Workflow;  

using Microsoft.SharePoint.WorkflowActions;  

[csharp] view
plaincopy

   

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

[csharp] view
plaincopy

public static DependencyProperty SiteUrlProperty = DependencyProperty.Register("SiteUrl",typeof(string), typeof(CreateSurveyList), new PropertyMetadata(""));  

        [DescriptionAttribute("Url of site where survey is to be created")]  

        [BrowsableAttribute(true)]  

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]  

        [ValidationOption(ValidationOption.Required)]  

        public string SiteUrl { get { return ((string)(base.GetValue(CreateSurveyList.SiteUrlProperty))); } set { base.SetValue(CreateSurveyList.SiteUrlProperty, value); } }  

 

7. 在CreateSurveyList.cs中添加SurveyListNameProperty

[csharp] view
plaincopy

public static DependencyProperty SurveyListNameProperty = DependencyProperty.Register("SurveyListName",typeof(string), typeof(CreateSurveyList), new PropertyMetadata(""));  

       [DescriptionAttribute("Name for survey list")]  

       [BrowsableAttribute(true)]  

       [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]  

       [ValidationOption(ValidationOption.Required)]  

       public string SurveyListName { get { return ((string)(base.GetValue(CreateSurveyList.SurveyListNameProperty))); } set { base.SetValue(CreateSurveyList.SurveyListNameProperty, value); } }  

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

[csharp] view
plaincopy

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)   

       {   

           this.CreateSurveyLibrary();   

           return ActivityExecutionStatus.Closed;  

       }         

         

       private void CreateSurveyLibrary()   

       {   

           using (SPSite oSPSite = new SPSite(SiteUrl))  

           {   

               using (SPWeb oSPWeb = oSPSite.RootWeb)  

               {  

                   Guid ID = oSPWeb.Lists.Add(SurveyListName, SurveyListName + System.DateTime.Now.ToString(), SPListTemplateType.Survey);   

                   SPList oSPList = oSPWeb.Lists[ID]; oSPList.OnQuickLaunch = true; oSPList.Update();   

               }  

           }   

       }  

[csharp] view
plaincopy

   

9.为项目CreateActivityDemo添加强名



编译CreateActivityDemo,显示编译成功

 

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



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

[html] view
plaincopy

<WorkflowInfo>  

  <Actions Sequential="then" Parallel="and">  

    <Action Name="Create Survey List"  

        ClassName="CreateActivityDemo.CreateSurveyList"  

        Assembly="CreateActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=331ffcc01b13c340"  

        AppliesTo="all"  

        Category="Sundar Activity">  

      <RuleDesigner Sentence="Survey List Name %1 to site %2.">  

        <FieldBind Field="SurveyListName" Text="Survey List Name"  

           DesignerType="TextArea" Id="1"/>  

        <FieldBind Field="SiteUrl" Text="Url of base site" Id="2"  

           DesignerType="TextArea"/>  

      </RuleDesigner>  

      <Parameters>  

        <Parameter Name="SurveyListName" Type="System.String, mscorlib"  

      Direction="In" />  

        <Parameter Name="SiteUrl" Type="System.String, mscorlib"  

      Direction="In" />  

      </Parameters>  

    </Action>  

  </Actions>  

</WorkflowInfo>  

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



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





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

[html] view
plaincopy

<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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐