Save selected E-mail attachment from outlook using c#

Posted on 2009-05-13
Last Modified: 2012-05-06

My name is Jeremy and I'm trying to make an addin in outlook 2007 to be able to save selected attachment directly in a specific folder. I've tried a lot of stuff but I'm only able to save all attachments from selected mail (see code below). I would like to save only the attachment I've selected...

Do you have any idea?

Many thanks.

private void button4_Click(object sender, EventArgs e)


            Outlook.Explorer currExplorer = App.ActiveExplorer();

            Outlook.MAPIFolder folder = App.ActiveExplorer().CurrentFolder;

            Outlook.Items inBoxItems = folder.Items;

            Outlook.MailItem item = null;



                Outlook.Selection selections = currExplorer.Selection;

                for (int i = 1; i == selections.Count; ++i)


                    object newEmail = (object)selections[i];

                    if (newEmail != null && (newEmail is Outlook.MailItem))


                        item = (Outlook.MailItem)newEmail;

                        if (item.Attachments.Count > 0)


                            for (int j = 1; j <= item.Attachments.Count; j++)


                                item.Attachments[j].SaveAsFile(@"C:\TestFileSave\" +item.Attachments[j].FileName);






            catch (Exception ex)


                string errorInfo = (string)ex.Message.Substring(0, 11);

                if (errorInfo == "Cannot save")


                    MessageBox.Show("Please create destination folder");




Open in new window

Question by:Jerem1981
LVL 83

Accepted Solution

CodeCruiser earned 500 total points
ID: 24386598
You could develop a form which would show all the attachements in a list to the user. The user can then select which one to save. You can not determine the selected attachement from Outlook.

Author Comment

ID: 24392704
ok, thanks for your reply. I've done this. I've inserted a listview and then I take the attachment name from this list and I compare ti know wich one to save.



Expert Comment

ID: 25117227
I have created a similar list view, but I would like to display the size of each attachment in the listview. Can this be done without saving the attachments?

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn on intranet settings 1 37
Run time Error 4 34
exchane, outlook 8 36
Facial recognition to look through the whole database for a person 3 40
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now