0

I have the following code inside our console application, to loop through a list of number and query the SharePoint list which is inside a modern communication site:

foreach (var r in allrequests.requests)

{

    Console.WriteLine("Entered foreach ");

    Console.WriteLine("RequestID= "+ r.id);

    CamlQuery camlQuery2 = new CamlQuery();

    Console.WriteLine("CAML initiaited" + r.id);

    r.id = "1";

    camlQuery2.ViewXml = "<View><Query><Where><Eq><FieldRef Name='RiskRequestIDNew'/><Value Type='Text'>" + r.id + "</Value></Eq></Where></Query></View>";

    Console.WriteLine("CAML ViewXML" + r.id);

    ListItemCollection oListItems2 = context.Site.RootWeb.GetList(RisksiteUrl + "Lists/RiskManagement/").GetItems(camlQuery2);

    Console.WriteLine("CAML GetItems" + r.id);

    context.Load(oListItems2);

    Console.WriteLine("Context load" + r.id);

    context.ExecuteQuery();

    Console.WriteLine("execute second CAML");

Now when the code reach context.ExecuteQuery(); it will raise this error:

Specified argument was out of the range of valid values.Parameter name: index

6
  • Try adding context.ExecuteQuery(); after foreach loop. May 20, 2021 at 14:32
  • @GaneshSanap same error i am unable to execute the CAML query.. i checked the internal names of the list columns and the list and they are valud
    – John John
    May 20, 2021 at 14:35
  • First try getting list like: List oList = context.Site.RootWeb.Lists.GetByTitle("RiskManagement"); Then get list items from ListItemCollection oListItems2 = oList.GetItems(camlQuery2); May 20, 2021 at 14:41
  • @GaneshSanap did not have any change
    – John John
    May 20, 2021 at 14:44
  • @GaneshSanap i almost spent 2 days on this .. i am planning to opne a case with MS
    – John John
    May 20, 2021 at 14:56

0

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.

Browse other questions tagged or ask your own question.