Cant differentiate between MailItem and MeetingItem in NewMailEx
I am developing an addin using c#. I am able to receiv开发者_如何学Pythone notifications whenever i get any item in my inbox.
this.Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(olApp_NewMail);
private void olApp_NewMail(String itemCollection)
{
string [] strNewItems;
strNewItems = itemCollection.Split(',');
foreach (string newItem in strNewItems)
{
Outlook.MailItem mail = (Outlook.MailItem)Application.Session.GetItemFromID(newItem, Type.Missing);
string old_subj = mail.Subject;
string old_body = mail.Body;
MessageBox.Show(old_subj);
}
}
but the problem is in the event handler i am not able to distinguish whether it is mail item or meeting item. How should i do it?
thanks in advance.
Regards, Jeeva
Can you not do something like:
object item = Application.Session.GetItemFromID(newItem, Type.Missing);
Outlook.MailItem mailItem = item as Outlook.MailItem;
if (mailItem != null)
{
...
}
else
{
Outlook.MeetingItem meetingItem = item as Outlook.MeetingItem;
if (meetingItem != null)
{
...
}
}
精彩评论