Question

I'm trying to query an SPList object using a CAML query (see code below).

SPQuery queryGetExistingTargetTask = new SPQuery();
queryGetExistingTargetTask.Query = string.Format(@"<Where><Eq><FieldRef Name=""TaskID""></FieldRef><Value Type=""Text"">{0}/Value></Eq></Where>", System.Security.SecurityElement.Escape(Convert.ToString(sourceTask["TaskID"])));
SPListItemCollection matchedTargetTasks = destinationList.GetItems(queryGetExistingTargetTask);

if (matchedTargetTasks.Count == 1) {...}

The SPList.GetITems call isn't throwing an error and it does return a SPListItemCollection Object. However, when I try to access any of the properties on the collection they throw an unhelpful error (see image below).

enter image description here

I'm fairly new to SharePoint development, so there is a good chance I am doing something very wrong here. Can you guys see anything obviously wrong with this code?

What I've tried so far:
- I confirmed that the destinationList (an SPList) is a valid instance of the correct list.
- Checked and re-checked the query in CAML builder

Note: This particular query should might (and will in my demo data) return no hits. However, I'd assume it would still return an object with a 0 value in the count property. Or am I mistaken about that?

Was it helpful?

Solution

Your CAML query is missing an angle bracket before /Value.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top