I want to get attached files from a mail into streams type. But how to create the stream ? I'm correctly getting mail items (content, subject, attached files). Referring to the following link : EWS Managed API : Getting attachment I tried to do the following :
int nbAttachments = message.Attachments.Count;
FileAttachment[] attachedFiles = new FileAttachment[nbAttachments];
for (int i=0; i < nbAttachments; i++)
{
attachedFiles[i] = message.Attachments[i] as FileAttachment;
}
for (int i = 0; i < attachments.Length; i++)
{
if (attachments[i].Name != null)
{
AttachmentCreationInformation infoAttachment = new AttachmentCreationInformation();
attachments[i].Load(infoAttachment.ContentStream);
infoAttachment.FileName = attachments[i].Name;
newItem.AttachmentFiles.Add(infoAttachment);
}
}
Ok don't worry I make a lot of test and manage exceptions but it's not relevant to put all the code here.
Some precisions :
- newItem is a List item from a SharePoint website. And I need an AttachmentCreationInformation type to add an attached file to this item.
I found this post : MSDN Forum and trying the following method :
FileStream stream = new FileStream(attachments[i].Name, FileMode.Open);
byte[] byteArray = new byte[stream.Length];
stream.Read(byteArray, 0, Convert.ToInt32(stream.Length));
stream.Close();
(Here my text is broken as I cannot convert it as code format so sorry for the italics ... out of luck today)
But it search the attachment on the local drive ...
Please help me
Basically I can't get how my attachment[i] can be added to a FileStream var...
Thanks a lot, really.