This documentation is archived and is not being maintained.

How to: Save Attachments from Outlook E-Mail Items

Note Required applications

The code example in this topic can be compiled only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005


    Visual Studio Team System

  • Microsoft Office Outlook 2003


This code does not compile if you use the VSTO 2005 SE version of the Outlook 2003 add-in project template. For more information, see Getting Started Programming Application-Level Add-ins.

This example saves e-mail attachments to a specified folder.


private void ThisApplication_Startup(object sender, System.EventArgs e)
    this.NewMail += new Microsoft.Office.Interop.Outlook

private void ThisApplication_NewMail()
    Outlook.MAPIFolder inBox = this.ActiveExplorer()
    Outlook.Items inBoxItems = inBox.Items;
    Outlook.MailItem newEmail = null;
    inBoxItems = inBoxItems.Restrict("[Unread] = true");
        foreach (object collectionItem in inBoxItems)
            newEmail = collectionItem as Outlook.MailItem;
            if (newEmail != null)
                if (newEmail.Attachments.Count > 0)
                    for (int i = 1; i <= newEmail
                       .Attachments.Count; i++)
                            (@"C:\TestFileSave\" +
    catch (Exception ex)
        string errorInfo = (string)ex.Message
            .Substring(0, 11);
        if (errorInfo == "Cannot save")
            MessageBox.Show(@"Create Folder C:\TestFileSave");

Compiling the Code

This example requires:

  • A folder named TestFileSave at the root of the C directory.

See Also