예제 #1
0
        /// <summary>
        /// Open an item in outlook folder
        /// </summary>
        /// <param name="item">Outlook item used to open</param>
        public static void DisplayAndCloseItem(object item)
        {
            try
            {
                Outlook.Application outlookApp = new Outlook.Application();
                object[]            args       = new object[] { };
                object retVal = item.GetType().InvokeMember("Class", BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty, null, item, args);
                Outlook.OlObjectClass outlookItemClass = (Outlook.OlObjectClass)retVal;
                switch (outlookItemClass)
                {
                case Outlook.OlObjectClass.olMail:
                    Outlook.MailItem omail = (Outlook.MailItem)item;
                    omail.Display(false);
                    omail.Close(Outlook.OlInspectorClose.olSave);
                    break;

                case Outlook.OlObjectClass.olDocument:
                    Outlook.DocumentItem odocument = (Outlook.DocumentItem)item;
                    odocument.Display(true);
                    odocument.Close(Outlook.OlInspectorClose.olSave);
                    break;

                case Outlook.OlObjectClass.olRecurrencePattern:

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Update items properties
        /// </summary>
        /// <param name="item">The target item</param>
        public static void UpdateItemProperties(object item)
        {
            try
            {
                object[] args   = new object[] { };
                object   retVal = item.GetType().InvokeMember("Class", BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty, null, item, args);
                Outlook.OlObjectClass outlookItemClass = (Outlook.OlObjectClass)retVal;
                switch (outlookItemClass)
                {
                case Outlook.OlObjectClass.olMail:
                    Outlook.MailItem omail = (Outlook.MailItem)item;
                    omail.Categories = "黄色类别";
                    omail.Save();
                    break;

                case Outlook.OlObjectClass.olDocument:
                    Outlook.DocumentItem odocument = (Outlook.DocumentItem)item;
                    odocument.Categories = "黄色类别";
                    odocument.Save();
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }