[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Save selected E-mail attachment from outlook using c#

Posted on 2009-05-13
3
Medium Priority
?
2,276 Views
Last Modified: 2012-05-06
Hello,

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.

Jerem
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;
 
            try
            {
                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

0
Comment
Question by:Jerem1981
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 24386598
Jeremy,
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.
0
 

Author Comment

by:Jerem1981
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.

Thanks,

Jeremy
0
 

Expert Comment

by:Lobo133
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?
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
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…

656 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