SAVE Message attachment to disk folder

Aug 19, 2013 at 3:24 PM
Hello Pavel...

How to save mail attachment (one or more per mail) to local folder disc?
Is there any function like mail.Save (path....) or something like that. Here is piece of sample code I want...

if (m.Attachments.Count > 0)
{
   foreach (var attachment in m.Attachments)
   {
               // attachment.Save //Implement here code for saving attachment
    }
}
Coordinator
Aug 19, 2013 at 8:39 PM
Hi vladang,

to save the attachment to a given folder you can use the method Attachment.SaveFile(string folderPath):
foreach (var attachment in m.Attachments)
{
         attachment.SaveFile(@"C:\FolderWithAttachments\");
}
Another options is accessing the property Attachment.FileData and write the byte array directly to disk.

I recommend you taking a look at the sample application, it has sample code for all major tasks.



Best regards,

Pavel Azanov
Aug 19, 2013 at 11:56 PM
Thanks Pavel. This is nice. Just another question regarding on attachments. Is it possible somehow to get URL link for some attachment, something like:

https:\www.mail.google.com\lakjsdlj....picture.jpg

If it is possible, I can use that link outside of application, for download attachment from Gmail
Coordinator
Aug 20, 2013 at 11:35 AM
It is not possible to get a direct link to an attachment. So if you want to share the attachment with someone, you have to upload it somewhere yourself and share the link you get.