I am trying to get all the files which is modified or added yesterday from SharePoint document library using below code.

            List list = clientContext.Web.Lists.GetByTitle(listName);
            CamlQuery camlQuery = new CamlQuery();
            camlQuery = new CamlQuery();
            camlQuery.ViewXml =
                "<View Scope='Recursive'>"
                 + "  <Query>"
                 + "    <Where>"
                 + "<Geq>"
                 + "<FieldRef Name='Modified' />"
                 + "<Value Type='DateTime' IncludeTimeValue='False'>"
                 + "<Today OffsetDays='" + ConfigurationManager.AppSettings.Get("OffsetDays") + "' />"
                 + "</Value>"
                 + "</Geq>"
                 + "    </Where>"
                 + "  </Query>"
                 + "</View>";

            ListItemCollection listCol = list.GetItems(camlQuery);
            int cnt = listCol.Count;
            foreach (var item in listCol)
                      TestingFiles(clientContext, item.FieldValues["FileDirRef"].ToString());

Please note that the value of OffsetDays is -1. But with the above code I am getting all the files instead only yesterdays files. Any idea what went wrong in my code.

  • I'm not able to read the CAML query, and that's probably where the issue is. – Oak3 Jul 11 '18 at 6:29
  • Hi Martijin, Can you please check now. – girish Jul 11 '18 at 6:49
  • At least it's readable, but I don't have a solution for you. There are CAML query builder tools available, maybe that helps? Otherwise I've found that adding or removing the <View> tags makes a difference. – Oak3 Jul 11 '18 at 6:55
  • Thanks Martijin, CAML query builder tool(CAMLDESIGNER 2013) does not have option to query inside the folder with date criteria. View tag cant be remove since I need the recursive. – girish Jul 11 '18 at 7:15
  • any progress on this issue? – Celophysis Aug 10 '18 at 9:40

Have you tried replacing <Geq></Geq> with <Eq></Eq>. Based on my interpretation of your situation, that is what you need to change.

  • Hi James, what needs to be replaced? can you please explain. – girish Jul 11 '18 at 8:34
  • Hi Sorry, i was on my way home and i forgot the code tag so it got stripped out. Please see updated answer – James Randal Jul 11 '18 at 8:50
  • Hi James, I replaced <Geq></Geq> with <Eq></Eq> but still it fetching all the files. I guess recursive causing the issue. Without recursive how do i get all the files from folders and subfolders. – girish Jul 11 '18 at 15:36

Your Answer

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

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