使用C#CSOM创建UserCustomAction

时间:2018-01-11 06:59:28

标签: sharepoint-2013 csom

在SharePoint 2013中工作。尝试将UserCustomAction添加到EditForm。

            List custom = web.Lists.GetByTitle("custom");
        UserCustomActionCollection UserActions = custom.UserCustomActions;
        ctx.Load(UserActions);
        ctx.ExecuteQuery();
        UserCustomAction CreateEmailAction = custom.UserCustomActions.Add();
        CreateEmailAction.RegistrationId = "{0BF934CE-0175-4E9D-BA6A-F58B7B1F2A89}";
        CreateEmailAction.RegistrationType = UserCustomActionRegistrationType.List;
        CreateEmailAction.Title = "HT Edit form Create email";
        CreateEmailAction.Location = "CommandUI.Ribbon.EditForm";
        CreateEmailAction.Group = "Actions";
        CreateEmailAction.Sequence = 1000;
        CreateEmailAction.CommandUIExtension = Properties.Resources.ribbon_editmeeting;
        CreateEmailAction.Update();
        ctx.ExecuteQuery();

XML代码:

<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">

      

  <Button Id="Ribbon.Documents.New.RibbonTest"
          Command="Notify"
          Sequence="0"
          Image16by16="/_layouts/images/NoteBoard_16x16.png"
          Image32by32="/_layouts/images/NoteBoard_32x32.png"
          Description="Uses the notification area to display a message."
          LabelText="Notify hello"
          TemplateAlias="o1"/></CommandUIDefinition></CommandUIDefinitions>

             

发生错误&#39; Microsoft.SharePoint.Client.ServerException失败   的HResult = 0x80131500   Message =不支持设置此属性。 {8F405B73-81C3-47C9-A07F-8899B57F09F9}的值已设置且无法更改。&#39;

如果我省略了RegistrationID行,代码就会成功完成,但不会创建任何操作。

1 个答案:

答案 0 :(得分:1)

1)RegistrationID是指操作将注册的列表。由于您要通过以下行添加自定义操作:

    UserCustomAction CreateEmailAction = custom.UserCustomActions.Add();

(其中自定义引用List)该部分是为您完成的。通过尝试重置该值,您可以完成错误。

2)使用&#34;列表项菜单&#34;的位置行动有效:

    UserCustomActionCollection UserActions = custom.UserCustomActions;
    ctx.Load(UserActions);
    ctx.ExecuteQuery();
    UserCustomAction CreateEmailAction = custom.UserCustomActions.Add();

    CreateEmailAction.Title = "HT Edit form Create email";

    CreateEmailAction.Location = "EditControlBlock";

    CreateEmailAction.Group = "Actions";
    CreateEmailAction.Sequence = 1000;
    CreateEmailAction.Update();
    ctx.ExecuteQuery();

所以我认为第二部分如果没有创建则与创建UI以触发按钮有关。可能有更多资源将按钮添加到编辑表单 在这里:This 和 在这里:https://sharepoint.stackexchange.com/q/103696

3)自定义操作基本上调用URL,因此您还需要设置将激活的操作的URL。这也可以是一个工作流程。例如:

    sendDocumentAction.Url = String.Format("~site/_layouts/15/wfstart.aspx?List={{ListId}}&ID={{ItemId}}&SubscriptionID={0}", newSubscription.Id);

其中newSubscription是要激活的工作流程订阅