将SharePoint 2010的workflow custom activity升级到SharePoint 2013遇到的问题

        前几天需要升级一个自定义的workflow activity,从支持SharePoint 2010的版本,升级到支持SharePoint 2013。 Branch代码出来之后,在VS工程中直接升级,之后编译,部署一切都很顺利,但是在测试的时候出现问题了。

        问题是这样的:打开SharePoint Designer 2013,新建一个workflow,在workflow里使用自定义的activity,定义好了之后,保存,然后发布的时候,Designer报了一个错误:

“Errors were found when compiling the workflow. The workflow files were saved but cannot be run.” 具体的信息是“The type or namespace name xxx could not be found (are you missing a using directive or an assembly reference?)”。

        我查了一下才知道(请参见点击打开链接),web.config文件中的<authorizedTypes>结构变了,在SharePoint 2013中加了一个子节点<targetFx>,因此需要将自定义的activity的authorizedType加到这个子节点中才行。

        以下是2010中的配置文件和2013中的配置文件的对比:

        SharePoint 2010:

<System.Workflow.ComponentModel.WorkflowCompiler>
  <authorizedTypes>
      <authorizedType Assembly="Microsoft.Office.Workflow.Actions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.Office.Workflow.Actions"TypeName="*"Authorized="True" />
      <authorizedType Assembly="MyActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567"Namespace="MyActions"TypeName="*"Authorized="True" />
  </authorizedTypes>
  <authorizedRuleTypes>
      <authorizedType Assembly="Microsoft.SharePoint.WorkflowActions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.SharePoint.WorkflowActions"TypeName="WorkflowCodeTypeReferenceExpression"Authorized="True" />
  </authorizedRuleTypes>
</System.Workflow.ComponentModel.WorkflowCompiler> 
        SharePoint 2013:
<System.Workflow.ComponentModel.WorkflowCompiler>
  <authorizedTypes>
    <targetFx version="v4.0">
      <authorizedType Assembly="Microsoft.Office.Workflow.Actions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.Office.Workflow.Actions"TypeName="*"Authorized="True" />
      <authorizedType Assembly="MyActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567"Namespace="MyActions"TypeName="*"Authorized="True" />
    </targetFx>
  </authorizedTypes>
  <authorizedRuleTypes>
    <targetFx version="v4.0">
      <authorizedType Assembly="Microsoft.SharePoint.WorkflowActions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.SharePoint.WorkflowActions"TypeName="WorkflowCodeTypeReferenceExpression"Authorized="True" />
    </targetFx>
  </authorizedRuleTypes>
</System.Workflow.ComponentModel.WorkflowCompiler>

以下是正确的修改配置文件的代码:

var service = SPWebService.ContentService;
var addModification = new SPWebConfigModification();
addModification.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes/targetFx";
addModification.Name= "authorizedType[@Assembly='MyActions'][@Namespace='MyActions'][@TypeName='*'][@Authorized='True']";
addModification.Owner= "MyActions";
addModification.Sequence= 0;
addModification.Type= SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
addModification.Value= @"<authorizedType Assembly=""MyActions""Namespace=""MyActions"" TypeName=""*""Authorized=""True"" />";
 service.WebConfigModifications.Add(addModification);
service.Update();
service.ApplyWebConfigModifications();




       

        

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值