我正在关注下一个项目:http://www.thorntontechnical.com/tech/sharepoint/sharepoint-2010-context-menu-item-with-custom-code
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>所以..。在SafeControl中我们可以在Web.config文件中找到我们的程序集
要执行的类
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包。带有Execute Package选项的ECB菜单出现在所有具有dtsx类型的文件中。因此,当我在底部单击时,事件不起作用...我不知道我该怎么做..。任何帮助我们的人都将不胜感激。
发布于 2012-02-14 03:24:34
尝试在SiteAction菜单中创建单独的操作:
ECB菜单是使用异步请求动态填充的,因此当页面发布时,不会创建ECB菜单的控件,也不会触发它们的事件。虽然总是呈现站点操作控件,因此可以处理回发。
发布于 2012-10-26 18:49:45
重新访问您提到的页面:
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元素中的属性ControlAssembly和ControlClass。这不是在他的帖子里做的,而是在评论中提到的(我试过了,它起作用了)。
还请注意他的博客文章中的其他评论:“缺点是控件现在会加载到任何地方,所以您必须确保除了使用__EVENTTARGET过滤的代码外,没有其他代码。”这在他的示例中已经实现了,但仍然值得注意。
https://stackoverflow.com/questions/9263336
复制相似问题