I am new to Outlook Addin development. I was writing a simple application that printed out the name of the folder that an email was dragged into. IE: Inbox to Subfolder in Inbox. The issue I have is that sometimes the correct MailItem.Parent.Name is returned but the majority of the time its the source folder and not the destination. I dont understand why this might be because the event should be firing for the ItemAdd on the destination.
Here is some code:
public Microsoft.Office.Interop.Outlook.Application OutlookApplication;
public Inspectors OutlookInspectors;
public Inspector OutlookInspector;
public MailItem OutlookMailItem;
private MAPIFolder inboxFolder;
private MailItem msg;
private Folder fdr;
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
OutlookApplication = application as Microsoft.Office.Interop.Outlook.Application;
OutlookInspectors = OutlookApplication.Inspectors;
OutlookInspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(OutlookInspectors_NewInspector);
inboxFolder = this.OutlookApplication.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
foreach (Folder f in inboxFolder.Folders)
{
f.Items.ItemAdd += new ItemsEvents_ItemAddEventHandler(InboxItems_ItemAdd);
}
}
void InboxItems_ItemAdd(object Item)
{
msg = Item as MailItem;
fdr = msg.Parent as Folder;
MessageBox.Show("Folder Name: " + fdr.Name);
}