从 SharePoint 功能区调用隐藏代码

5 sharepoint sharepoint-2010

我在我的 SharePoint 功能区中创建了一个自定义操作按钮,现在我试图从该按钮调用一些 C# 代码。我一直无法找到有关如何执行此操作的任何详细信息。有谁知道如何做到这一点或有任何关于如何做到这一点的好信息?不确定它会有所帮助,但这是我的自定义操作按钮的代码。谢谢!

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

  <CustomAction

    Id="CustomRibbonButton"
    RegistrationId="101"
    RegistrationType="List"
    Location="CommandUI.Ribbon"
    Sequence="5"
    Title="Move Documents">

    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
          <Button
              Id="Ribbon.Documents.New.MoveButton"
              Alt="Move Documents"
              Sequence="5"
              Command="Move_Button"
              Image32by32="/_layouts/images/Skynet/WinEarth32x32.png"
              Image16by16="/_layouts/images/Skynet/WinEarth16x16.png"
              LabelText="Move Documents"
              TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>

      <CommandUIHandlers>
        <CommandUIHandler
          Command="Move_Button"
          CommandAction="javascript:alert('SharePoint 2010 makes me angry!');" />
      </CommandUIHandlers>

    </CommandUIExtension>
  </CustomAction>

</Elements>
Run Code Online (Sandbox Code Playgroud)

Eri*_*ens 1

CommandUIHandler 可以执行 JavaScript(包括客户端对象模型),但如果您想执行服务器对象模型代码,您可以使用Andrew Connell 的这篇 MSDN 文章中描述的回发机制。他创建了一个 Web 部件来侦听由功能区按钮生成的回发事件。

或者,您可以实现一个 Web 服务并从 JavaScript CommandUIHandler 调用该服务(ajax 调用)。这里使用的是这种方法。(不再访问2016-02-01)