none
UnauthorizedAccessException When Trying To Save Email Attachments RRS feed

  • Question

  • When I try to save an email attachment to a folder like c:\outlook usingOutlook.Attachment.SaveAsFile method, the following exception gets thrown:

    System.UnauthorizedAccessException was unhandled by user code Message=Cannot save the attachment. You don't have appropriate permission to perform this operation.

    What causes this problem and how do I solve it?

    Tuesday, January 22, 2013 9:07 PM

Answers

  • If this is a protected version of Windows (later than Windows XP) and Outlook was not started using administrative permissions that would be expected. Pick a different location to try to save the file that isn't protected by the operating system.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Radi_88" <=?utf-8?B?UmFkaV84OA==?=> wrote in message news:b6243784-d6cb-412c-a053-17af43adab7b...

    When I try to save an email attachment to a folder like c:\outlook usingOutlook.Attachment.SaveAsFile method, the following exception gets thrown:

    System.UnauthorizedAccessException was unhandled by user code Message=Cannot save the attachment. You don't have appropriate permission to perform this operation.

    What causes this problem and how do I solve it?


    Ken Slovak MVP - Outlook
    Wednesday, January 23, 2013 2:48 PM
    Moderator

All replies

  • What filename do you pass as the parameter?

    Do you use fully qualified path?


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

    Tuesday, January 22, 2013 9:20 PM
  • Best would to be show us your full code responsible for saving attachments
    Wednesday, January 23, 2013 6:19 AM
  • If this is a protected version of Windows (later than Windows XP) and Outlook was not started using administrative permissions that would be expected. Pick a different location to try to save the file that isn't protected by the operating system.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Radi_88" <=?utf-8?B?UmFkaV84OA==?=> wrote in message news:b6243784-d6cb-412c-a053-17af43adab7b...

    When I try to save an email attachment to a folder like c:\outlook usingOutlook.Attachment.SaveAsFile method, the following exception gets thrown:

    System.UnauthorizedAccessException was unhandled by user code Message=Cannot save the attachment. You don't have appropriate permission to perform this operation.

    What causes this problem and how do I solve it?


    Ken Slovak MVP - Outlook
    Wednesday, January 23, 2013 2:48 PM
    Moderator
  • I get the same error message, but I'm saving to an unprotected folder. It will save the first 200 email attachments, but then I get the same error again.Thanks!
    Friday, June 21, 2013 1:39 AM
  • What is your code? Are you using multiple dot notation? Do you release Outlook objects as soon as you are done with them using Marshal.ReleaseComObject?

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

    Friday, June 21, 2013 1:55 AM
  • I have tried releasing them, but I still get a message indicating that the folder to which I'm saving the file won't work. Before running the macro, I have read-write privileges. After I run the macro, I have read-only privileges and no more files can be written to that folder. The error message given is "error=-2147467259 Cannot save the attachment. Cannot create file...." I'm puzzled. Thanks for your suggestion.

    Friday, June 21, 2013 9:27 PM
  • I was having the same problem (sorry for my english)

    you need put path + atch.FileName like:

    "c:/user/" & atch.FileName

    Thursday, September 26, 2019 6:08 PM