Hi Guys!
I have a MOSS 2007 site that is used for Resource Reservation.
At this site there's a list for resources, reservations, and many others as needed. I also have all forms and Dataviews is needed to get a better usability.
So, to don't allow the same resource to be reserved at a conflicting schedule, I created the following Event Receiver to validate this condition:
using (SPSite oSPSite = new SPSite(properties.WebUrl)) { SPWeb oSPWeb = oSPSite.OpenWeb(); SPList oSPList = oSPWeb.Lists["Reservations"]; SPQuery oSPquery = new SPQuery(); // Query used to compare input (Resource, StartTime, EndTime) data with list data. oSPquery.Query = "<Where><Or><And><Eq><FieldRef Name='Resource' LookupId='TRUE' /><Value Type='Lookup'>" + properties.AfterProperties["Resource"] + "</Value></Eq><And><Leq><FieldRef Name='StartDateTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + properties.AfterProperties["StartDateTime"] + "</Value></Leq><Geq><FieldRef Name='EndDateTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + properties.AfterProperties["EndDateTime"] + "</Value></Geq></And></And><And><Eq><FieldRef Name='Resource' LookupId='TRUE' /><Value Type='Lookup'>" + properties.AfterProperties["Resource"] + "</Value></Eq><And><Lt><FieldRef Name='StartDateTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + properties.AfterProperties["EndDateTime"] + "</Value></Lt><Gt><FieldRef Name='EndDateTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + properties.AfterProperties["StartDateTime"] + "</Value></Gt></And></And></Or></Where>"; SPListItemCollection oListItemColl = oSPList.GetItems(oSPquery); // By this CAML filter, if there's a resource reserved at the same time range, it will be blocked! if (oListItemColl.Count > 0) { properties.Cancel = true; properties.ErrorMessage = "The selected resource was previously reserved by another user for the same date and time period. Please select another resource, or choose another date/ time."; } } }Now I'm having problems since the list Reservation has more than 2000 items...
I take a look to some msdn documents like this one:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.rowlimit.aspx
But when I implement a query recursion by ListItemCollectionPosition, it isn't working as I need.
(I tried to remove the CAML query and it was worked fine - querying all items).
By this way, I have the impression if I use the CAML query + recursion suggested above, it will only query the first 2000 items.
How's the better way to solve this problem?
Ps: beginner developer :D
Thanks!!
Tarcísio Gambin | MCP, MCTS, MCITP, ITILv3
www.tarcisiogambin.net