Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have an 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;
    VanField.Update(true);
    list.Update(true);
    web.Update();

    web.AllowUnsafeUpdates = safeUpdates;
    base.ListAdded(properties);
}

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

The event is an sychronous event. THe field is an Taxonomy field, maybe that's the problem.

share|improve this question
    
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

1 Answer 1

You are missing this line :

VanField.PushChangesToLists = true;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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