Hi Ken,
Thank you for your quick answer and patience. the new inspector is firing
but I try to add a button through this newinspector handler and the code
contains commandbars, the new inspector stops firing:
here's my code:
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");
string messageClass = "";
if (i.CurrentItem is Outlook.MailItem)
{
mitem = i.CurrentItem as Outlook.MailItem;
messageClass = mitem.MessageClass;
}
Outlook.Selection outlookSelection =
applicationObject.ActiveExplorer().Selection;
/****************/
/****************/
/****************/
/****************/
try
{
oCommandBars = i.CommandBars;
}
catch (System.Exception)
{
// Outlook has the CommandBars collection on the
Explorer object.
object oActiveExplorer;
oActiveExplorer =
applicationObject.GetType().InvokeMember("ActiveExplorer",
BindingFlags.GetProperty, null, applicationObject, null);
oCommandBars =
(CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars",
BindingFlags.GetProperty, null, oActiveExplorer, null);
}
// Set up a custom button on the "Standard" commandbar.
try
{
oStandardBar = oCommandBars["Standard"];
}
catch (System.Exception)
{
oStandardBar = oCommandBars["Database"];
}
/****************/
/****************/
/****************/
/****************/
if (outlookSelection.Count > 0)
{
object omissing = System.Reflection.Missing.Value;
selectedItem = outlookSelection[1];
if (selectedItem is Outlook.MailItem)
{
if (messageClass == "IPM.Note")
{
selectedmsg = (selectedItem as
Outlook.MailItem);
selectedmsg.Read += new
Outlook.ItemEvents_10_ReadEventHandler(Read_Mail);
selectedmsg.Open += new Outlook.ItemEvents_10_OpenEventHandler(Open_Mail);
Word.Document document =
(Word.Document)i.WordEditor;
if (mxcrm == true &&
document.Kind.ToString().Equals("wdDocumentEmail") &&
this.applicationObject.ActiveExplorer().Application.Name.Equals("Outlook"))
addsendbutton();
}
}
}
}
private void Open_Mail(ref bool cancel)
{
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;
//remove old menus...
foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM") || caption.EndsWith("Send and
Upload to CRM"))
{
control.Delete(null);
}
}
try
{
addpopupandbutton();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception= " +
ex.Message);
}
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - End");
}
private void Read_Mail()
{
CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;
//remove old menus...
foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM"))
{
control.Delete(null);
}
}
CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - End");
}
public CommandBars oCommandBars;
public CommandBar oStandardBar;//at class level
When I remove the part of the code surrounded by the stars
/****************/, the new inspector gets fired. the same problem appears
if I put the star code in openmail or read mail, then the open and read
dont fire anymore. the part surrounded by /****************/ is important
to add the button on the commandbar of the mailitem.
Any idea what I am missing here or doing wrong? I am very new to this
field.
Thanks a lot,
Nc
Submitted via EggHeadCafe - Software Developer Portal of Choice
Simple .NET HEX PixelColor Utility
http://www.eggheadcafe.com/tutorial...f52bc1/simple-net-hex-pixelcolor-utility.aspx