August 13, 2010

Getting a List’s Base View Programmatically

This is something that took me a little while to figure out but then realized how easy it was :-)
To get the base view from a list, you need to get the view that has an empty string for the name, weird right!!
So this is how you do it:

SPView view = list.Views[string.Empty];

Update: this will only work if the list is a custom list (meaning: you created the list definition and specified a baseview with ID 0).

Update
This only applies to custom list created using custom list definition where you have specified a view with BaseID 0