Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,518 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have all my in a list
public partial class CalendarPageViewModel(GraphServiceClient graphClient) : ObservableObject { public ObservableCollection<Event> CalendarEvents { get; set; } = []; public async Task FetchCalendarEventsAsync() { var graphEventsResponse = await graphClient.Me.Events.GetAsync(); if(graphEventsResponse != null) { foreach(var items in graphEventsResponse?.Value!) { CalendarEvents.Add(items); } }
But that is giving me all the event from the calendar, but I don't care about past events, I want to get the events from today going forward
I tried this code
var today = DateTime.UtcNow.ToString("o"); var graphEventsResponse = await graphClient.Me.Events.GetAsync(requestConfiguration => { requestConfiguration.QueryParameters.Filter = $"start/DateTime ge {today}"; requestConfiguration.QueryParameters.Orderby = new List<string> { "start/DateTime asc" }; }); if (graphEventsResponse != null) { CalendarEvents.Clear(); foreach (var item in graphEventsResponse.Value!) { CalendarEvents.Add(item); } }
and I get the error of debugger is not attach to this project error
Your filter parameter is incorrect. The comparison should be against a string value in quotes. Try something like this.
var today = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); var graphEventsResponse = await graphClient.Me.Events.GetAsync(config => { config.QueryParameters.Filter = $"start/DateTime ge '{today}'"; config.QueryParameters.Orderby = new[] { "start/DateTime asc" }; });