2

I've googled that it can be in case when query is not well-formed. But I'm verifying it for several hours and didn't find any mistake. Problem is common: query doesn't filters and returns all data.

I have no idea what is wrong, because I checked this query in Stramit CAML viewer and it worked fine.

        private static SPListItemCollection GetItemsForThisUserAndEvent(SPList list)
        {
            const string queryMask = 
@"<Where>
    <And>
        <Eq>
            <FieldRef Name='{0}' LookupId='TRUE' />
            <Value Type='Lookup'>{1}</Value>
        <Eq>
        <Eq>
            <FieldRef Name='{2}' LookupId='TRUE' />
            <Value Type='User'>{3}</Value>
        <Eq>
    </And>
<Where>";

            var query = string.Format(queryMask, MemberListFieldLookupEventName, SPContext.Current.ListItem.ID,
                                                 MemberListFieldLogin, SPContext.Current.Web.CurrentUser.ID);
            return list.GetItems(query);
        }

1 Answer 1

6

Query in your case is a string, which means that you are using the SPList.GetItems(String[]) overload.

That method accept a list of fields to load, not a query. You should be using one of the overloads that accepts an actual SPQuery object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.