2012-02-13 115 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進行過濾的代碼之外。這已經在他的例子中實現,但仍然值得注意。