In this post we will discuss how to modify All Items view by using SharePoint object model.
You can also check my previous posts on Add script reference dynamically through code in SharePoint [Read here
], Custom timer job sharepoint 2010 [Read here
] and Add webpart zone outside PlaceHolderMain in SharePoint 2010 [Solution here
Views are ways to display SharePoint list or document library data. The default view for each list or document library is the All Items view. You can check this article
to read more about different views in SharePoint.
Below is the code to modify the ALl Items view of a custom list.
using (SPSite site = new SPSite("http://SiteURL"))
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists["MyCustomList"];
SPView view = list.Views["All Items"];
SPViewFieldCollection fieldCol = view.ViewFields;
After executing this code FirstName, LastName and Email columns will be added to the All Items view.