如何将参数值从一个事件接收器传递到另一个自定义类的方法 [英] How to pass a Parameter value from one event receiver to another custom Class's method

查看:67
本文介绍了如何将参数值从一个事件接收器传递到另一个自定义类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个类[itemadded,itemupdated eventreceiver方法]类.现在,我想传递几个参数,包括splistitem,currentlist,currentweb和另外两个字符串参数.

I am having an class [ itemadded, itemupdated eventreceiver methods] class .Now I want to pass few parameters including splistitem,currentlist, currentweb, another 2 string parameters .

############################################## ############### 3

##############################################################3

 公共替代无效ItemAdded(SPItemEventProperties属性)
        {
            base.ItemAdded(properties);
            SPUser currUser = properties.Web.CurrentUser;
            this.EventFiringEnabled = false;
           试试
            {
                    SPSite parentSite =新的SPSite(properties.SiteId);
                    SPUserToken systemToken = parentSite.SystemAccount.UserToken;
                   字符串siteURL = properties.RelativeWebUrl;
                    SPListItem currentitemAdded = properties.ListItem;
                    SPList父母pList = currentitemAdded.ParentList;
                    impersonateTest(siteURL,currentitemAdded,parentspList);
            }
           捕获(异常expinAssignPermission_SGSFLISTITEM_PDL)
            {
                Logger.WriteLog(Logger.Category.High,"GrantPermissionsToUsersCurrentPDLFROM_SGSFListItem_EvtR​​ecvr",expinAssignPermission_SGSFLISTITEM_PDL.Message.ToString()+"__" + expinAssignPermission_SGSFLISTITEM_PDL.StackTrace.             }

            this.EventFiringEnabled = true;

        }

 public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);
            SPUser currUser = properties.Web.CurrentUser;
            this.EventFiringEnabled = false;
            try
            {
                    SPSite parentSite = new SPSite(properties.SiteId);
                    SPUserToken systemToken = parentSite.SystemAccount.UserToken;
                    string siteURL = properties.RelativeWebUrl;
                    SPListItem currentitemAdded = properties.ListItem;
                    SPList parentspList = currentitemAdded.ParentList;
                   impersonateTest(siteURL,currentitemAdded,parentspList);
            }
            catch (Exception expinAssignPermission_SGSFLISTITEM_PDL)
            {
                Logger.WriteLog(Logger.Category.High, "GrantPermissionsToUsersCurrentPDLFROM_SGSFListItem_EvtRecvr", expinAssignPermission_SGSFLISTITEM_PDL.Message.ToString() + "__" + expinAssignPermission_SGSFLISTITEM_PDL.StackTrace.ToString());
            }

            this.EventFiringEnabled = true;

        }

              private void  impersonateTest(siteURL,currentitemAdded,parentspList);

             private void  impersonateTest(siteURL,currentitemAdded,parentspList);

{

  字符串strPCFILPFieldVal ="Y";
                    string  AselectedprojectStatusValue = string.Empty;

  FetchPCFListFieldValues(currentItemPCF,oSPList,tokenWeb,objspauthor,tokenSite,strPCFILPFieldVal,AselectedprojectStatusValue,userValue_Editor);

   string strPCFILPFieldVal ="Y";
                   string  AselectedprojectStatusValue =string.Empty;

  FetchPCFListFieldValues(currentItemPCF, oSPList, tokenWeb, objspauthor, tokenSite, strPCFILPFieldVal, AselectedprojectStatusValue, userValue_Editor);

}

以上是我在itemadded()中的方法,我需要定义该方法           

the above is my method in itemadded() and i need to define the method              

FetchPCFListFieldValues(currentItemPCF,oSPList,tokenWeb,objspauthor,tokenSite,strPCFILPFieldVal,AselectedprojectStatusValue,userValue_Editor);

FetchPCFListFieldValues(currentItemPCF, oSPList, tokenWeb, objspauthor, tokenSite, strPCFILPFieldVal, AselectedprojectStatusValue, userValue_Editor);

在一个单独的类中.

我的意思是,我将在同一程序集/命名空间"目录中创建一个名为PCFPDLUpdate的单独类.此事件接收者的

I mean, I will create a separate class called PCFPDLUpdate within the same "assembly/namespace" of this eventreceiver 

公共类PCFPDLUpdate
    {

       公共PCFPDLUpdate(){}

       私有无效UpdatePCLILPFieldinPDL(SPListItem CurrentListItem,SPList CurrentList,SPWeb CurrentWeb,SPUser objspauthor,SPSite CurrentSite,字符串paramstrPCFILPFieldVal,SPFieldUserValue paramuserValue_Editor)
        {

            //对另一个文档库项目进行一些操作,那是从前一个参数传递过来的

public class PCFPDLUpdate
    {

        public PCFPDLUpdate() { }

        private void UpdatePCLILPFieldinPDL(SPListItem CurrentListItem, SPList CurrentList, SPWeb CurrentWeb, SPUser objspauthor, SPSite CurrentSite, string paramstrPCFILPFieldVal, SPFieldUserValue paramuserValue_Editor)
        {

            //do some manipulation on another doc lib item, thats passed as a parameter from the previous

          //eventrceiver

          //eventrceiver

         }

         }

 }//命名空间的结尾

 } //end of namespace

现在我的问题是如何创建类[在同一名称空间中]的对象  PCFPDLUpdate ,并使用以下方法执行名为  UpdatePCLILPFieldinPDL()的方法currentlistitem,string1,string2,objSPAuthor作为参数 ?

now my question is how can I create a object of the class [ in the same namespace]  PCFPDLUpdate and execute a method called  UpdatePCLILPFieldinPDL() with currentlistitem, string1, string2, objSPAuthor  as parameters ?

我的疑问是,由于itemadd方法驻留在从spitemeventreceiver继承的 类中,因此我还应该为自定义类继承spitemeventreceiver父类

my doubt is , since the itemadded methods are residing in the  class thats  inheriting from spitemeventreceiver, should I also inherit the spitemeventreceiver parent class, for my custom class

PCFPDLUpdate?如果没有,我需要继承任何其他接口或其他东西,这样,我就可以获得在itemadded()内设置的正确currentsplistitem对象

PCFPDLUpdate ? if not, any other interfaces or something do I need to inherit , such that, i can get the correct currentsplistitem object thats set inside the itemadded()

这可能吗?


推荐答案

您要做什么?您是否要在添加项目和更新项目的事件接收者之间传递参数?

What are you trying to do?  Do you want to pass the parameters between item added and item updated event receivers?

如果要这样做,请确保您的列表/库已将两个事件接收器都部署到该列表/库.如果您在itemadded事件接收器中更新了一个项目,它将触发一个itemupdated事件处理程序.这样,您可以在itemupdated事件中访问当前项目 使用SPItemEventProperties的处理程序.除当前项目外,如果您要将任何其他元数据传递给itemupdated事件处理程序,则可以在同一列表中创建隐藏列以存储要传递的信息,也可以使用任何其他自定义项 实现相同的逻辑.

If you want to do that, make sure your list/library has both event receivers deployed to that. If you update an item in itemadded event receiver, it will trigger an itemupdated event handler. By doing so, your current item can be accesed in itemupdated event handler using SPItemEventProperties . Apart from the current item, if you want to pass any other metadata to itemupdated event handler, either you can create hidden columns in same list to store information to be passed or make use of any other custom logic to achieve the same.


这篇关于如何将参数值从一个事件接收器传递到另一个自定义类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆