none
i write a code for saving th attachmens from outlook.its working fine with 2007 but i am not getting the email attachments from outlook2010.becoz in that gmail is taking a separate inbox and outlook too so how can i access my gmail account items? RRS feed

  • Question


  •             const string destinationDirectory = @"C:\TestFileSave";

                if (!Directory.Exists(destinationDirectory))
                {
                    Directory.CreateDirectory(destinationDirectory);
                }
               
                MAPIFolder inbox = this.Application.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
                Items inboxItems = inbox.Items;
                MessageBox.Show(inboxItems.Count.ToString());
                MAPIFolder inbo = this.Application.ActiveExplorer().AccountSelector.SelectedAccount.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
                MessageBox.Show(inbo.Items.Count.ToString());
                
                
                    foreach (object collectionItem in inboxItems)
                    {
                        MailItem newEmail = collectionItem as MailItem;
                        if (newEmail == null) continue;

                        if (newEmail.Attachments.Count > 0)
                        {
                            for (int i = 1; i <= newEmail.Attachments.Count; i++)
                            {
                                string filePath = Path.Combine(destinationDirectory, newEmail.Attachments[i].FileName);
                                newEmail.Attachments[i].SaveAsFile(filePath);
                            }
                        }
                    
                }
    Thursday, December 13, 2012 7:45 AM

Answers

All replies

  • Session object has Stores collection - each store corresponds to separate account in outlook. So iterate through stores and on each store invoke Store.GetDefaultFolder(OlDefaultFolders.olFolderInbox); Everything else without changes
    Thursday, December 13, 2012 7:49 AM
  • Session object has Stores collection - each store corresponds to separate account in outlook. So iterate through stores and on each store invoke Store.GetDefaultFolder(OlDefaultFolders.olFolderInbox); Everything else without changes
    can u say little bit clearly...........
    Thursday, December 13, 2012 7:53 AM
  • http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._namespace.stores(v=office.14).aspx

    pseudo code:

    foreach(Store in Session.Stores)

    {

    inbox = Store.GetDefaultFolder(olInbox)

    //everything else without changes

    }

    • Marked as answer by krish233 Thursday, December 13, 2012 8:41 AM
    Thursday, December 13, 2012 8:29 AM

  • foreach(Store in Session.Stores)

    {

    inbox = Store.GetDefaultFolder(olInbox)

    //everything else without changes

    }

    i am not able get that getdefau;tfolder method undr store class

    • Marked as answer by krish233 Wednesday, December 19, 2012 10:17 AM
    Thursday, December 13, 2012 11:10 AM