SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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?

share|improve this answer
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 '13 at 9:14
Great, and I assume you also do a list.Update() before adding the viewfields? – Robert Lindgren Apr 11 '13 at 9:15
Using the field object directly (it is created earlier in the function), also doesn't work. – TZHX Apr 11 '13 at 9:15
Yes; list.Update() is called numerous times before this point, and after. – TZHX Apr 11 '13 at 9:16
Did you check if list.View[0] is actually a visible html view of your list? – Elitza Atanasova Apr 11 '13 at 9:37

Your Answer


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.