2012-02-13 57 views
0

我之后的下一个项目:http://www.thorntontechnical.com/tech/sharepoint/sharepoint-2010-context-menu-item-with-custom-codedoPostBack没有发射

Elements.xml的

<?xml version="1.0" encoding="utf-8"?> 
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
    <CustomAction Id="SPTest.CustomMenuItem.ButtonClicked" 
      RegistrationType="FileType" 
      RegistrationId="dtsx" 
      Location="EditControlBlock" 
      ImageUrl="/_layouts/IMAGES/DOCLINK.GIF" 
      Sequence="600" 
      Title="Execute Package" 
      Description="Executed Selected Package" 
      ControlAssembly="SPTest.CustomMenuItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=beb14bc625e99e7f" 
      ControlClass="SPTest.CustomMenuItem.CustomItemAction" 
      > 
<UrlAction Url="javascript:__doPostBack('SPTest.CustomMenuItem.CustomItemAction', {ItemId});" /> 
</CustomAction> 
</Elements> 

PACKAGE.TEMPLATE.XML

<?xml version="1.0" encoding="utf-8"?> 
<Solution xmlns="http://schemas.microsoft.com/sharepoint/"> 
<Assemblies> 
    <Assembly Location="SPTest.CustomMenuItem.dll" DeploymentTarget="GlobalAssemblyCache"> 
    <SafeControls> 
     <SafeControl Assembly="SPTest.CustomMenuItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=beb14bc625e99e7f" 
       Namespace="SPTest.CustomMenuItem" TypeName="*" Safe="True"  SafeAgainstScript="False" /> 
    </SafeControls> 
    </Assembly> 
</Assemblies> 
</Solution> 

所以......在Web.config文件我们可以在SafeControl中找到我们的组件

CLASS TO EXECUTE

using System.IO; 
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using Microsoft.SharePoint; 
    using Microsoft.SharePoint.WebControls; 

    namespace SPTest.CustomMenuItem 
    { 
     public class CustomItemAction : SPLinkButton 
     { 
      protected override void OnLoad(EventArgs e) 
      { 
       this.EnsureChildControls(); 
       base.OnLoad(e); 
       if (this.Page.Request["__EVENTTARGET"] == "SPTest.CustomMenuItem.ButtonClicked") 
       { 
        int itemId = Convert.ToInt32(this.Page.Request["__EVENTARGUMENT"]); 
        System.IO.TextWriter writer = new StreamWriter(@"C:\XXXXX\XXXXX\XXXXX\custommenuoutput.txt", true); 
        writer.WriteLine("Event Fired at:" + DateTime.Now.ToLongTimeString() + ": Item ID:" + itemId.ToString()); 
        writer.Close(); 
       } 
      } 
     } 
    } 

如您所见,目标是执行在Sharepoint上分配的SSIS包。具有执行包选项的ECB菜单出现在所有具有dtsx类型的文件中。因此,当我点击这个底部时,这个事件不起作用......我不知道我必须做什么......任何帮助都将会得到满足。谢谢!!

回答

0

尝试创建SiteAction菜单单独行动:

< CustomAction ID为 “SPTest.CustomMenuItem.CustomActionsDispatcher” 的GroupId = “SiteActions” 位置= “Microsoft.SharePoint.StandardMenu”
序列=” 1000" 标题= “自定义操作调度”
ControlAssembly = “SPTest.CustomMenuItem,版本= 1.0.0.0, 文化=中性公钥= beb14bc625e99e7f”
ControlClass = “SPTest.CustomMenuItem.CustomItemAction” >
</CustomAction >

欧洲央行菜单人口动态使用异步请求,所以当页面上发布,不会创建ECB菜单控件,并为他们的事件不会被触发。虽然站点操作控件总是呈现,所以可以处理回发。

+0

我将我的代码替换为您的,没有任何反应...... SiteActions组中没有任何选项出现 – 2012-02-14 10:17:53

+0

选项不应在SiteActions组中显示 - 它应该在那里但不可见。为了使它可见,你应该为它提供标题。选择自定义操作时,网页是否会刷新(是否真的发布)?如果是的话,尝试添加**保护覆盖无效OnInit(EventArgs e)**到CustomItemAction并在里面设置断点 - 如果页面刷新时没有触发断点,则表示CustomItemAction不是页面控制树,不能处理回发。 – 2012-02-15 06:13:52

0

重温你提的页面:

http://www.thorntontechnical.com/tech/sharepoint/sharepoint-2010-context-menu-item-with-custom-code

他的编辑(16/02/2012)修复了这个问题( “我们还需要告诉的SharePoint加载控制”):

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
<Control ControlAssembly="SPTest.CustomMenuItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken={PublicKeyToken}" 
ControlClass="SPTest.CustomMenuItem.CustomItemAction" Sequence="50" Id="AdditionalPageHead"/> 
<CustomAction ... 

然后您可以省略CustomAction元素中的属性ControlAssemblyControlClass。这不是在他的文章中完成的,而是在评论中提到的(我试过了,它的工作原理)。

请注意他的博客文章中还有哪些评论说:“缺点是控件现在无处不在,因此您必须确保没有其他代码,除了您使用__EVENTTARGET进行过滤的代码之外。这已经在他的例子中实现,但仍然值得注意。