Programmatically get SPList items from a SPView

Another tip that you're sure to find some use for:

Because SharePoint list (SPList) views (SPView) don't contain SPListItems or SPListItemCollections, if you want to programmatically retrieve list items from a list in the order specified by a view you've created you have to do it as follows (I've ommited, try-catch blocks and extraneous code to give you just the bare necessities)

SPListItemCollection coll = spWeb.Lists["ListName"].GetItems(spWebInstance.Lists["ListName"].Views["ViewName"]);


where spWeb is a SPWeb you've opened up from an SPSite object. and "ListName" and "ViewName" are the names of your lists and views, respectively.

Comments

Kelly Ford said…
Thanks for the example.

Popular posts from this blog

Programmatically Update Page Layouts

Microsoft Virtualilzation Headaches

ERROR: Failed to create feature receiver...