Link to home
Start Free TrialLog in
Avatar of AJDeveloper
AJDeveloper

asked on

Error when saving attachment in outlook using vsto addin

Hi,
I am developing an outlook 2010 vsto addin using Visual Studio 2010

I am trying to save attachments the I send or receive to a specific folder .If the mail-item has proper attachments, like when the user clicks on the attachment button, it is working fine ,but, if the mail-item has attachment that is embedded such inline image(image on the mail body itself ) ,I get the a COM exception, with the message: “Cannot save the attachment. Cannot add the attachment; no data source was provided."
My inquiry ,why the error is occurring and how can I check for proper attachment and not embedded attachment ,the code is like this :

myAttachments = Mail.Attachments

        For Each Attch As Outlook.Attachment In myAttachments
            Att = Attch.DisplayName.ToString
            Attch.SaveAsFile(“C:\Temp\" & Att)
        Next

Any idea or help is appreciated
Avatar of AJDeveloper
AJDeveloper

ASKER

Any help ,please!
Avatar of TommySzalapski
Can you put the Att string out to a message box and see what it says? I tried diong it in VBA (I don't have VSTO) and it works fine.
I used Attch.FileName not Attch.DisplayName.
Thanks Tommy .The problem is the issue doesnt happen all the time .I will try what you suggested but i want to know how to only check for proper attachment and not embdeded pictures because they will be saved as well
ASKER CERTIFIED SOLUTION
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Tommy ,I already included Try -Catch block to trap any error but it is frustrating because there should be a way to control or know which attahcments are 'proper' and which are embedded .I assume now there is no way to determine between them ?
Nope. There is nothing in the Attachment object that says which it is.
If you attach a picture the normal way and embed the same picture the two attachment objects are bit for bit identical (I tested this myself).
The error handling is the only way.