Friday, November 21, 2008

SPList with SPQuery

The OM was used to create an SPQuery object that contained the query criteria. That object was then used to against an instance of the list in a SPList object. The results of the query were returned by calling the GetItems method on the SPList object.
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()

'create our query
Dim curQry As SPQuery = New SPQuery()

'configure the query
curQry.Query = "
Hotel
"
curQry.RowLimit = 100

'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.GetItems(curQry)

'enumerate the items in the list
For Each curItem As SPListItem In curItems
'do something with each match
Next

No comments: