Saving attchment as file

-- -- 666 Reputation points
2021-05-07T17:25:36.277+00:00

Hi

I am using below code to access mail file attachments. I have two questions;

  1. How can I only get unread messages?
  2. How can I save file attachment into a file?

Thanks

Regards

      var inboxMessages = await graphClient
        .Users[user.Id]
        .MailFolders.Inbox
        .Messages
        .Request()
        .GetAsync();

      foreach(Microsoft.Graph.Message message in inboxMessages) {

        if (message.HasAttachments == true) {
          var attachments = await graphClient
            .Users[user.Id]
            .Messages[$ "{message.Id}"]
            .Attachments
            .Request()
            .GetAsync();

          foreach(var attachment in attachments) {
            if (attachment is FileAttachment) {
              FileAttachment fileAttachment = attachment as FileAttachment;

              //Save fileAttachment content to file here

            }
          }
        }
      }
Microsoft Graph SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
737 questions
Microsoft Graph Mail API
Microsoft Graph Mail API
A Microsoft API that supports accessing data in users' primary mailboxes and in shared mailboxes.
684 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Deva-MSFT 2,231 Reputation points
    2021-05-11T17:52:59.013+00:00
    No comments