Question

2 part question,

  • In my EmailReceived event receiver, what is the best way to pull out and save any attachments (whether they are .doc, .pdf, etc)
  • and then, when I have those attachments, save them to a different list

Currently in my event receiver I am pulling meta data successfully. Just not sure how to manage the attached files.

Thanks!

Était-ce utile?

La solution

SPEmailMessage class (object of which is passed to EmailReceived method of your customer email event receiver). It has got Attachments property which contain all the attachments.

public override void EmailReceived(SPList list, SPEmailMessage message, string receiverData)
 {
      // Get all the attachments in the root folder
      foreach (SPEmailAttachment attachment in message.Attachments)
       {
             byte[] attachmentArray = new byte[attachment.ContentStream.Length];
             attachment.ContentStream.Read(attachmentArray, 0, (int)attachment.ContentStream.Length);
             list.RootFolder.Files.Add(attachment.FileName, attachmentArray);
      }
 }
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top