none
Save mailitem attachment when file is https://1drv.ms/.... RRS feed

  • Question

  • In a mail I have several of attachments.

    All these attachments are like this...

    When I do a Outlook.Attachment.Outlook.Attachment.SaveAsFile, it saves a link and not the actual file.

    How can I save the actual file to local disk?

    Thanks

    CLARIFICATION:

    The files above are links to files stored in Microsoft OneDrive, so when I try to download, it downloads as links. I need to download the files - not the links.

    • Edited by M O J O Monday, September 24, 2018 11:11 AM
    Monday, September 24, 2018 7:13 AM

All replies

  • Hi MOJO,

    I've assumed you would to download these files as your picture. Please try the following code:

     private void SaveMailAttachments(Outlook.MailItem mailItem)
            {
                Outlook.Attachments attachments = mailItem.Attachments;
                if (attachments != null && attachments.Count > 0)
                {
                    for (int i = 1; i <= attachments.Count; i++)
                    {
                        Outlook.Attachment attachment = attachments[i];
                        if (attachment.Type == Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue)
                        {
                            string filename = Path.Combine(@"d:\", attachment.FileName);
                            attachment.SaveAsFile(filename);
                        }
                    }
                }
            }
    For more information, please see, Downloading Attachments of Outlook in c#

    Regards,

    Simon


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, September 24, 2018 10:48 AM
    Moderator
  • Hi Simon

    Sorry for not being clear.

    The files are links to Mirosoft Onedrive - so all I download is a link, not the physical file.

    I need to download the images - not links.

    Monday, September 24, 2018 11:10 AM
  • Hi MOJO,

    Sorry for missing the point. 

    In fact, you just would like to download Pic file from OneDrive(you have links), right?  I've assumed you have a full path e.g. http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png. You can use the following code:

    using System.Net;
    //...
    WebClient Client = new WebClient ();
    Client.DownloadFile("http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png", @"C:\folder\stackoverflowlogo.png");

    However, for the OneDrive, I think you should use REST API for this. For more information, please see these links below:

    Downloading and uploading files on OneDrive (REST)

    How to download files from OneDrive


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Tuesday, September 25, 2018 9:23 AM
    Moderator
  • You for the shared web attachments, you need to parse the generated URL file to extract the link and then download the file from the server explicitly in your code.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, September 25, 2018 8:00 PM
  • Hi MOJO,

    Did you solved your problem? Please feedback to us if you have any updates for this. Thanks for your understanding.

    Regards,

    Simon


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Friday, September 28, 2018 2:23 AM
    Moderator