I am trying to modify a view for a list in a Feature Event Receiver. The list is created in the same function; and the columns all added to it. When I look in the List Settings via the web interface, the Fields are there, but the following code doesn't seem to work:

SPView view = list.Views[0];

Going from the MSDN Documentation on the subject I really can't see what I'm doing wrong. No exceptions are being thrown, the list only has the one view, so... any thoughts?

1 Answer 1


I usually retreive the View via it's ID like this:

 var view = list.Views[list.DefaultView.ID];

Or like this:

SPView view = list.DefaultView;

But to get it by Views[0] should work to.

What comes to mind is that the Field name may possibly be incorrect. Have you tried debugging your code to see if it breaks?

  • The field name is correct; if the field name is incorrect it throws an error (I tested this by changing the field name to something incorrect).
    – TZHX
    Apr 11, 2013 at 9:14
  • Great, and I assume you also do a list.Update() before adding the viewfields? Apr 11, 2013 at 9:15
  • Using the field object directly (it is created earlier in the function), also doesn't work.
    – TZHX
    Apr 11, 2013 at 9:15
  • Yes; list.Update() is called numerous times before this point, and after.
    – TZHX
    Apr 11, 2013 at 9:16
  • 2
    Did you check if list.View[0] is actually a visible html view of your list? Apr 11, 2013 at 9:37

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.