Sunday, March 23, 2008

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.


Anonymous said...

Thanks a lot!

Kelly Ford said...

Thanks for the example.

Restoring a lot of files from the Recycle Bin

I had a customer who accidentally synched a (very large) SP Online library and then decided they didn't want the files on their PC anymo...