1

I have created a simple SharePoint 2013 solution and added event receiver. When I am in visual studio, i hit F5, solution is deployed and event receiver works. However, when I publish the solution (.wsp), add it into solutions, activate the solution, activate the feature in the site collection admin, it just does not work.

I found out, that after I use "deploy" in VS13, then event receiver starts working just like it was working during debugging. Do you have any idea why please? :) I am banging my head what could be wrong...

thank you very much

Here is my very crude code:

 public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);
        base.EventFiringEnabled = false;

        String curListName = properties.ListTitle;

        if (curListName == "ListOfAddedItem")
        {
            string internalName = properties.ListItem.Fields["Title"].InternalName;

            //Turn off event firing during item update
            base.EventFiringEnabled = false;

            SPListItem item = properties.ListItem;
            item[internalName] = "E:" + item[internalName];


            //getting second web
            string siteUrl = "issserver/sites/devsite";



            try
            {
                SPSite site = new SPSite(siteUrl);

                using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    site.AllowUnsafeUpdates = true;
                    SPList list = web.Lists["OtherList"];

                    list.Fields[SPBuiltInFieldId.ID].ReadOnlyField = false;

                    SPListItem Item = list.Items.Add();
                    Item[SPBuiltInFieldId.ID] = item["ID"];
                    Item["Title"] = item["Title"];
                    Item.Update();

                    list.Fields[SPBuiltInFieldId.ID].ReadOnlyField = true;
                }  
            }
            catch {
                item[internalName] = "cannot connect to the site";
            }


            item.Update();

            //clientContext.ExecuteQuery();

            base.EventFiringEnabled = true;
        }
    }

enter image description here enter image description here

6
  • Have you activated features related to your WSP solutions in site and site collection features? Jan 13, 2016 at 11:58
  • Hi Dikesh, yes I did. I have attached two screenshots to my original post. this is very strange.
    – Pedro
    Jan 13, 2016 at 12:08
  • What about site features? Have you added that event receiver in feature? Don't get me wrong. Just double check it.....:) Jan 13, 2016 at 12:10
  • it is not shown in site features as the solution scope is set to site - activation for site and all other subsites.
    – Pedro
    Jan 13, 2016 at 12:13
  • Please restart the SharePoint timer service & rest IIS before deployment of your solution.... It will work...
    – Hardik
    Jan 13, 2016 at 12:24

1 Answer 1

0

I think i found an error. My testing enviroment was local server and deployment server was office 365 sharepoint. i tried the simple code and it started to work. I guess i will have to start logging what exactly caused it :)

this code worked:

     public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);
        SPListItem _item = properties.ListItem;
        _item["Title"] = DateTime.Now.ToString();
        _item.Update();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.