0

I am having an issue when creating a WebProvisioned eventreceiver that activates a feature. However I am getting the "Save conflict - Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes." error.

The idea is that I have a custom site template and a feature that hides some fields from new and edit form on a generic list we created. I want the feature to be activated after the every subsite is created, so that it can modify an existing list on the template.

Here is my WebProvisioned method:

public override void WebProvisioned(SPWebEventProperties properties)
    {
        base.WebProvisioned(properties);

        SPWeb web = properties.Web;

        // Activate feature
        web.Features.Add(new Guid("1d128122-c13a-4a6a-9e09-9388535f51bb"));
    }

And here is the FeatureActivated method:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWeb web = properties.Feature.Parent as SPWeb;

        SPList lst = web.Lists.TryGetList("Statusbeskrivelse");
        if (lst != null)
        {
            //lst.EventReceivers.Add(SPEventReceiverType.ItemAdding, Assembly.GetExecutingAssembly().FullName, typeof(ListEventReceiver).FullName);

            // Hide KPI fields
            SPField customerField = lst.Fields.GetFieldByInternalName("KPI_x0020_Kunde");
            customerField.ShowInNewForm = false;
            customerField.ShowInEditForm = false;
            customerField.Update();

            SPField periodField = lst.Fields.GetFieldByInternalName("KPI_x0020_Periode");
            periodField.ShowInNewForm = false;
            periodField.ShowInEditForm = false;
            periodField.Update();

            SPField projectField = lst.Fields.GetFieldByInternalName("KPI_x0020_Projekt");
            projectField.ShowInNewForm = false;
            projectField.ShowInEditForm = false;
            projectField.Update();
        }
    }

I am getting the error on the first SPField.Update();

Can anyone help me with what is wrong? I tried reading this blog where he mentions that the method is asynchronous as standard and changing it to synchronous can help with save conflicts errors. I am however not creating several sites simultaneously, only one at the time...

Thanks for reading.

Anders

1 Answer 1

0

Ok. So this answer is long overdue, but here is what I found out.

Apparently the web that is created, has some code-behind to do that and a lot of other things, so that is why I was getting the error.

I could not do anything about that, so I instead created a thread to do my dirty work and waited 10 seconds before doing so.

Here is my implementation:

public override void WebProvisioned(SPWebEventProperties properties)
    {
        base.WebProvisioned(properties);

        SPWeb web = properties.Web;

        System.Threading.Thread t1 = new System.Threading.Thread(delegate()
        {
            System.Threading.Thread.Sleep(10000);

            web.Features.Add(new Guid("1d128122-c13a-4a6a-9e09-9388535f51bb"));
        }

        t1.Start();
    }

Your Answer

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

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