0

I have a list of Employee class which has empid and empname as property.

Now I want to construct a caml query IN clause where list column id in empid.

How can I write a foreach loop inside caml query and set each id in tag?

Thanks.

  • You need to include the SharePoint version as this is important for the available features of the CAML syntax. – Robert Kaucher Jun 2 '13 at 16:27
1

I am not sure which programming language you are using nor which version of SharePoint (2007, 20010, etc). But here is an example in C#. You should also check out Camlex.NET as Alex suggested. Here is a possible example for you, though:

    StringBuilder queryText = new StringBuilder(@"<Where><In><FieldRef Name = 'ID'/><Values>");
    foreach (var person in MyPeopleCollection)
    {
        queryText.Append(@"<Value Type = 'Number'/>");
        queryText.Append(person.Id);
        queryText.Append("</Values>");
    }
    queryText.Append(@"</In></Where>");
    SPListItemCollection Items = MyList.GetItems(new SPQuery(){QueryStringValueProvider = queryText });
|improve this answer|||||
  • Thanks Robert very much.Exactly same thing I was looking for. – user13408 Jun 3 '13 at 3:28
  • Glad I could help! – Robert Kaucher Jun 3 '13 at 12:46
1

I would suggest using Camlex.NET.

Camlex.NET simplifies creating of CAML queries for SharePoint by using expression. So you can easily construct a CAML query. Try it.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy