ClientContext API will not return items in Teams SharePoint site, works fine in SharePoint Online

25 views Asked by At

Would there be a difference in using the 'older' SharePoint ClientContext/CSOM based API against a site in SharePoint Online versus one that is a part of a Team?

I have a bit of code that works just fine when talking to a general SPO site.

string camlXML = "<View><Query><Where><And><Geq><FieldRef Name='EventDate' /><Value " +
                "Type='DateTime'>" + (DateTime.UtcNow.AddDays(daysPast * -1).ToString("o", System.Globalization.CultureInfo.InvariantCulture) +
                "</Value></Geq><Leq><FieldRef Name='EventDate'/><Value Type='DateTime'>" +
                DateTime.UtcNow.AddDays(daysForward).ToString("o", System.Globalization.CultureInfo.InvariantCulture)) +
                "</Value></Leq></And></Where></Query></View>";


using (var cc = new AuthenticationManager().GetACSAppOnlyContext(instance.url, instance.apiKey, instance.apiSecret))
{    
    Web web = cc.Web;
    var spTimezone = web.RegionalSettings.TimeZone;

    List eventsList = web.Lists.GetByTitle(instance.calendarTitle);
    CamlQuery query = new CamlQuery();
    var list = web.Lists;

    query.ViewXml = camlXML;
    ListItemCollection eventsItems = eventsList.GetItems(query);
    cc.Load(eventsItems);
    cc.ExecuteQuery();

    Logger.Info("Found " + eventsItems.Count + " items in " + instance.name);
}

But, if I run this against a site I am working on now, I get zero results. If I run against several sites I developed this code against (not tied to a Team) it works as expected and returns me a collection of list items.

I feel that my auth is working, as if I spell CalendarTitle wrong, I get an exception that List does not exist at URL.

I also can not seem to be able to see a list of all lists in the site, etc.

Is this due to a difference in this particular site? Why would I not be able to get any results, when it works fine on all of my other, non-Teams based sites?

1

There are 1 answers

1
Hilton Giesenow On

It might still be an authentication issue. Per this doc:

Using Azure ACS (Access Control Services) for SharePoint Online has been retired as of November 27th 2023...