Saving attchment as file

-- -- 872 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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,645 questions
{count} votes

1 answer

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