简体   繁体   中英

Event Receiver stop working

For some reason I was working on an event receiver when it stopped working. I am updating it and deploying from Visual Studio 2010 and it was previously working but it stopped when I was doing lookup fields. It is not working any more even if I remove the portion I just added. any ideas. thank you.

    `/// An item was added.
    /// </summary>
    public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);
        string fname = Convert.ToString(properties.AfterProperties["Title"]);
        string Cdate = Convert.ToString(properties.AfterProperties["CDate"]).Substring(2, 2);
        // ---- Lookup fields ----- 
        String lookupZF = "Office";
        String ZF = Convert.ToString(properties.ListItem[lookupZF]);
        SPFieldLookupValue ZFValue = new SPFieldLookupValue(ZF);
        // ------ End of lookup fields ----- 
        string FName = fname + Cdate; // + ZFValue;

        SPSecurity.RunWithElevatedPrivileges(delegate()
                       {
                           using (SPSite site = new SPSite(properties.Web.Site.ID))
                           {
                               using (SPWeb web = site.OpenWeb())
                               {
                                   web.AllowUnsafeUpdates = true;
                                   SPList CurrentList = web.Lists[properties.ListId];
                             SPListItem Litem = CurrentList.GetItemById(properties.ListItemId);

                                   Litem["Description"] = "update working ...!";
                                   Litem["Prop No."] = FName;

                                   Litem.Update();
                                   CurrentList.Update();

                                   web.AllowUnsafeUpdates = false;
                               }
                           }
                       });
    }`

我建议您在部署解决方案后检查“管理站点功能”中是否激活了该功能。

I had to use dateTime then get the year. for some reason I was getting empty or null string that stopped the excution of the code. here is what worked:

DateTime Cdate = DateTime.Parse(properties.ListItem["Created"].ToString());
string SDate = Cdate.Year.ToString().Substring(2, 2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM