Save attachments from Outlook 2003

Add-in Express™ Support Service
That's what is more important than anything else

Save attachments from Outlook 2003
 
chris smalls


Guest


Hi everyone. Im making an add-in for outlook 2003 with VS2005. Im looping through the inbox and saving the emails. This is working fine. The problem I am having is saving attachments. I cannot access the item property of mailItem.Attachments.

The compiler says: 'Interop.Outlook.Attachments' does not contain a definition for 'Item'

Does anyone know what I am missing?

Here is the code I am using.


private void adxCommandBarButton1_Click(object sender)
{
  Outlook.MAPIFolder inbox = OutlookApp.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
  Outlook.Items items = inbox.Items;
  Outlook.Attachment attachment = null;

  try
  {
    foreach (Outlook.MailItem mail in items)
    {
      for (int i = 1; i <= mail.Attachments.Count; i++)
      {
        attachment = mail.Attachments.Item(i);
        attachment.SaveAsFile("c:\test\" + attachment.FileName);
        Marshal.ReleaseComObject(attachment);
      }
    }
  }
  catch
  {
  } 
}


I would appreciate any help.

Thanks, Chris
Posted 07 Dec, 2006 10:42:55 Top
chris smalls


Guest


Ignore this please, I have just seen my mistake.

attachment = mail.Attachments[i];

:|
Posted 08 Dec, 2006 04:44:14 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Chris.

Thank you for the question.
Posted 08 Dec, 2006 12:01:23 Top