I have a listadded EventReceiver with the following code:

 public override void ListAdded(SPListEventProperties properties)
    SPWeb web = properties.Web;
    bool safeUpdates = web.AllowUnsafeUpdates;
    web.AllowUnsafeUpdates = true;
    SPList list = properties.List;

    SPField VanField  = list.Fields.GetFieldByInternalName("MyFieldName");
    VanField.ShowInEditForm = false;
    VanField.ShowInNewForm = false;

    web.AllowUnsafeUpdates = safeUpdates;

The problem I have is that the ShowInEditForm and ShowInNewForm not saved to the fields.

The event is a synchronous event. The field is an Taxonomy field, maybe that's the problem.

  • Are you sure that your EventReceiver is called after the list creation? Did you try to put a breakpoint in the method and debug it? – Norbert Dec 12 '12 at 11:18
  • Yes i'm sure. It's running the code – Active_t Dec 12 '12 at 11:23
  • I would try making this Added event synchronous. This way it will run 100% AFTER the list has been committed to the database. – Norbert Dec 12 '12 at 11:35
  • It's already synchronous – Active_t Dec 12 '12 at 11:42
  • ListAdded is not synchrous. ListAdding is. – Dominic Goulet Sep 4 '13 at 13:29

You are missing this line :

VanField.PushChangesToLists = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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