Friday, November 21, 2008

SPList with For/Each

The Office SharePoint Server 2007 object model (OM) was used to retrieve the list into an SPList object. Each item in the list was then enumerated with a For/Each loop until items were found that matched the search criteria.
The following sample code was used for this method.

'get the site
Dim curSite As SPSite = New SPSite("http://myPortal")

'get the web
Dim curWeb As SPWeb = curSite.OpenWeb()

'get our list
Dim curList As SPList = curWeb.Lists(New Guid("myListGUID"))

'get the collection of items in the list
Dim curItems As SPListItemCollection = curList.Items

'enumerate the items in the list
For Each curItem As SPListItem In curItems
'do some comparison in here to see if it's an item we need
Next

No comments: