Folder.Bind Method in Graph SDK client using C#

SAC_535 36 Reputation points
2022-05-04T11:59:44.96+00:00

We need folder.bind similar method in Graph SDK using C#.

Below method works with Outlook Exchange services but for O365 user its not working.

var msgRootFId = new EWS.FolderId(EWS.WellKnownFolderName.MsgFolderRoot, new EWS.Mailbox(SMTPAddress)); msgRoot = EWS.Folder.Bind(service, msgRootFId, EWS.BasePropertySet.IdOnly);

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

2 answers

Sort by: Most helpful
  1. Glen Scales 4,431 Reputation points
    2022-05-04T22:58:32.013+00:00

    The equivalent graph SDK method would be

     var msgRoot= .Users[SMTPAddress].MailFolders["MsgfolderRoot"].Request().GetAsync().GetAwaiter().GetResult();
    

    That should return the graph folder class. When you say something doesn't work you should always include any errors you receive as that will tell anybody looking at the problem what is going wrong. Eg the following would fail if you where using Delegate permission to access a Shared mailbox but didn't have the Mail.Read.Shared permissions


  2. Glen Scales 4,431 Reputation points
    2022-05-06T00:01:42.813+00:00

    var msgRootFId = new EWS.FolderId(EWS.WellKnownFolderName.MsgFolderRoot, new EWS.Mailbox(SMTPAddress));
    for this replacement is var msgRoot= .Users[SMTPAddress].MailFolders["MsgfolderRoot"].Request().GetAsync().GetAwaiter().GetResult();

    That's not correct all that line does in EWS is creates a FolderId object to be used in the next call which isn't' needed in Graph, it doesn't make any requests to EWS

    msgRoot = EWS.Folder.Bind(service, msgRootFId, EWS.BasePropertySet.IdOnly); what is method in Graph SDK?

    Folder Bind makes a GetFolder Request in EWS that returns the folder and with the property set your using it would only just return the id so

     var msgRoot= .Users[SMTPAddress].MailFolders["MsgfolderRoot"].Request().GetAsync().GetAwaiter().GetResult();
    

    Does exactly the same thing in the Graph eg it make a REST get and returns the MsgFolderRoot for that mailbox, if you want to limit it to just the Id then

    var msgRoot= .Users[SMTPAddress].MailFolders["MsgfolderRoot"].Request().Select("id")..GetAsync().GetAwaiter().GetResult();
    

    The Id's you get back will be different in that one is the EWSId for the Mailbox and the other is the RestId