0

I have Generated Microsoft Graph app in ASP.NET MVC platform, that I have downloaded from Microsoft Graph site. I need to access the shared mail folder not sure exactly how can I get that?? In the following code I can access my mailFolder but not shared mailfolder!

public static async Task<IEnumerable<MailFolder>> GetMailFolderAsync()
{
    var graphClient = GetAuthenticatedClient();
    var mailFolder = await graphClient.Me.MailFolders.Request().GetAsync();
    var sharedMailFolder = await graphClient.Users.Request().GetAsync();
    return mailFolder;
}

Also, I want to know in above code where I can pass the parameter to access next page or all pages??

private static GraphServiceClient GetAuthenticatedClient()
    {
        return new GraphServiceClient(
            new DelegateAuthenticationProvider(
                async (requestMessage) =>
                {
                    string signedInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                    SessionTokenStore tokenStore = new SessionTokenStore(signedInUserId,
                        new HttpContextWrapper(HttpContext.Current));

                    var idClient = new ConfidentialClientApplication(
                        appId, redirectUri, new ClientCredential(appSecret),
                        tokenStore.GetMsalCacheInstance(), null);

                    var accounts = await idClient.GetAccountsAsync();

                    var result = await idClient.AcquireTokenSilentAsync(
                        graphScopes.Split(' '), accounts.FirstOrDefault());

                    requestMessage.Headers.Authorization =
                        new AuthenticationHeaderValue("Bearer", result.AccessToken);
                }));
K.Z
  • 5,201
  • 25
  • 104
  • 240

1 Answers1

0

I think it is not possible to access shared folders I am investigating as well. In regards to the question of getting pages, as soon as you get the first request

public static async Task<IEnumerable<MailFolder>> GetMailFolderAsync()
{
    var graphClient = GetAuthenticatedClient();
    var mailFolder = await graphClient.Me.MailFolders.Request().GetAsync();
    var sharedMailFolder = await graphClient.Users.Request().GetAsync();
    return mailFolder;
}

then you can review for example, mailFolder.NextPageRequest, if it is not null then you can request it by doing mailFolder.NextPageRequest.GetAsync() and you can use it as a loop conditional

while(mailfoldersCollection != null) {
// Do your stuff with items within for(var folder in mailfoldersCollection) {}
// when read all items in CurrentPage then
if (mailFolder.NextPageRequest != null) {
mailfoldersCollection = await mailFolder.NextPageRequest.GetAsync();
}

hope it works for you!

El maik
  • 59
  • 6