从SharePoint Ribbon调用代码后台

5
我在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>
2个回答

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

另外,你可以实现一个Web服务,并从JavaScript CommandUIHandler(ajax调用)中调用它。 这种方法在此处被使用。(2016-02-01已不再可访问)


第二个链接已经失效。 - Burgi

0

我不确定这是否能帮到你,但是在我进行一些功能区工作时,我使用了http://quickdeploydoc.codeplex.com项目中的代码。我将用户发送到一个页面,然后再将其带回来。希望能有所帮助。

  <CustomAction Id="8CC3766E-1429-498c-9EEA-B2DFA784C360"
                RegistrationType="ContentType"
                RegistrationId="0x0101"
                Location="EditControlBlock"
                Title="Add to Quick Deploy"
                Sequence="1000"
                Description="Add this document to the next Quick Deploy job.">
    <UrlAction Url="javascript:window.location='/_layouts/QuickDeploy/QuickDeployDoc.aspx?SiteUrl={SiteUrl}&amp;ItemUrl={ItemUrl}&amp;returnUrl='+window.location" />
  </CustomAction>

protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                QuickDeploy quidkDep = new QuickDeploy();

                string siteUrl = Request["SiteUrl"];
                string webUrl = SPContext.Current.Web.Url;
                string itemUrl = Request["ItemUrl"];

                webUrl = siteUrl.Remove(0, webUrl.Length);

                quidkDep.QuickDeployment(siteUrl, webUrl, itemUrl);

                ClientScript.RegisterClientScriptBlock(this.GetType(), "GoBack", "function GoBack(){document.location='" + Request["returnurl"].ToString() + "';}", true);
            }
            catch (Exception ex)
            {
                throw new Exception("Could not save document to Quick Deploy job. " + ex.ToString());
            }
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接