Filter data from Microsoft graph

Eduardo Gomez3,611Reputation points
2025-04-26T16:19:58.76+00:00

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

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,518 questions
0 commentsNo comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor58,526Reputation points
    2025-04-27T02:42:30.16+00:00

    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" }; }); 
    0 commentsNo comments

Your answer