ACCESS FILES IN ONE DRIVE

Giorgio Sfiligoi 391 Reputation points
2025-03-17T18:07:46.8066667+00:00

I am elaborating on the samples https://github.com/Azure-Samples/ms-identity-dotnetcore-maui/tree/main

I added the scopes Files.Read, Files.ReadWrite, Files.ReadWrite.All with the goal to access my files.

                try
                {
                    var user = await PublicClientSingleton.Instance.MSGraphHelper.GetMeAsync();
                    if (user == null) await Shell.Current.DisplayAlert("Error", "Cannot find GraphUser", "OK");
                    else
                    {
                        if (user.Drive == null) await Shell.Current.GoToAsync("resultview?userdata=DRIVE NULL");
                        else await Shell.Current.GoToAsync("resultview?userdata=DRIVE OK");
                    }
                }
                catch (MsalUiRequiredException)
                {
                    await PublicClientSingleton.Instance.SignOutAsync();
                    await Shell.Current.GoToAsync("mainview");
                }

Here "resultview" is a page that is supposed to present the directory and the contents of my files. The snippet above reports "DRIVE NULL" therefore any attempt to call user.Drive.Root.... etc. will fail.

How can I access directories and files in my OneDrive?

I verified that user.DisplayName, user.Id return consistent information.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.