Bassem Murad
hi,
Thanks for the quick reply,
1 - Do you mean canel = true
i put it at the top of the event...and it disables the response the first time...
2 - i declared the mail item is at class level...still same problem...it runs the first time, doesnt run the second...
3- and yea, that is an old comment...it took me a while actually to understand what u where talking about..
here is how my code looks like...i try to show that menu item on all mails in all items..that is y i bind it on folderSwitch...
namespace
OutlookAddIn
{
public partial class OutlookAddIn
{
string MenuItemName = "Send to DB";
private Outlook.Explorer explorer = null;
private Outlook.MailItem MyMailItem;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = Application.Explorers.Application.ActiveExplorer();
explorer.SelectionChange +=
new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange);
Outlook.
MAPIFolder mapi = Application.ActiveExplorer().CurrentFolder;
foreach (object x in mapi.Items)
{
MyMailItem = x
as Outlook.MailItem;
if (MyMailItem != null)
{
Outlook.
Action newAction = MyMailItem.Actions[MenuItemName.ToString()];
if (newAction == null)
{
newAction = MyMailItem.Actions.Add();
newAction.Name = MenuItemName.ToString();
newAction.ShowOn = Outlook.
OlActionShowOn.olMenuAndToolbar;
newAction.Enabled =
true;
MyMailItem.Save();
}
MyMailItem.CustomAction +=
new Microsoft.Office.Interop.Outlook.ItemEvents_10_CustomActionEventHandler(mailItem_CustomAction);
}
}
mapi.GetExplorer(1).FolderSwitch +=
new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_FolderSwitchEventHandler(OutlookAddIn_FolderSwitch);
}
////////////////////////
void OutlookAddIn_FolderSwitch()
{
Outlook.
MAPIFolder mapi = Application.ActiveExplorer().CurrentFolder;
foreach (object x in mapi.Items)
{
MyMailItem = x
as Outlook.MailItem;
if (MyMailItem != null)
{
Outlook.
Action newAction = MyMailItem.Actions[MenuItemName.ToString()];
if (newAction == null)
{
newAction = MyMailItem.Actions.Add();
newAction.Name = MenuItemName.ToString();
newAction.ShowOn = Outlook.
OlActionShowOn.olMenuAndToolbar;
newAction.Enabled =
true;
MyMailItem.Save();
}
MyMailItem.CustomAction +=
new Microsoft.Office.Interop.Outlook.ItemEvents_10_CustomActionEventHandler(mailItem_CustomAction);
}
}
}
/////////////////////
void mailItem_CustomAction(object Action, object Response, ref bool Cancel)
{
Cancel =
true;
MyMailItem = (Outlook.
MailItem)Response;
MyMailItem.Close(Microsoft.Office.Interop.Outlook.
OlInspectorClose.olDiscard);
try
{
Outlook.
Action mailAction = (Outlook.Action)Action;
switch (mailAction.Name)
{
case "Send to DB":
performAction();
break;
default:
MessageBox.Show("error...");
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
////////////////////////////
private void performAction()
{
MyMailItem = explorer.Selection[1]
as Outlook.MailItem;
// do stuff with subject and other mail objects
}
/////////
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
}
}
Thanks in advance for the help...