Esempio n. 1
0
        public OutlookItem Create(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            OutlookItem retVal = null;

            Outlook._AppointmentItem appItem = obj as Outlook._AppointmentItem;
            if (obj is Outlook._AppointmentItem)
            {
                retVal = new OutlookAppointment(_listener, (Outlook._AppointmentItem)obj);
            }
            else if (obj is Outlook.RecurrencePattern)
            {
                retVal = new OutlookRecurrencePattern(_listener, (Outlook.RecurrencePattern)obj);
            }
            else if (obj is Outlook.Exception)
            {
                retVal = new OutlookException(_listener, (Outlook.Exception)obj);
            }
            else if (obj is Outlook.Recipient)
            {
                retVal = new OutlookRecipient(_listener, (Outlook.Recipient)obj);
            }
            else if (obj is Outlook.MAPIFolder)
            {
                retVal = new OutlookFolder(_listener, (Outlook.MAPIFolder)obj);
            }

            return(retVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the outlook folder from path.
        /// </summary>
        /// <param name="outlookNS">The outlook NS.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public OutlookFolder GetOutlookFolderFromPath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            OutlookFolder retVal = null;

            if (this.InvokeRequired)
            {
                Func <string, OutlookFolder> func = this.GetOutlookFolderFromPath;
                retVal = (OutlookFolder)this.Invoke(func, path);
            }
            else
            {
                Outlook.MAPIFolder oMapiFolder = null;
                Outlook.NameSpace  oNs         = null;
                try
                {
                    oNs = this._addinModule.OutlookApp.GetNamespace("MAPI");

                    string[] folders = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    if (folders.Length != 0)
                    {
                        oMapiFolder = oNs.Folders.Item(folders[0]);
                        for (int i = 1; i < folders.Length; i++)
                        {
                            Outlook.MAPIFolder oTmpMapiFolder = oMapiFolder.Folders.Item(folders[i]);
                            if (oTmpMapiFolder != null)
                            {
                                Marshal.ReleaseComObject(oMapiFolder);
                                oMapiFolder = oTmpMapiFolder;
                            }
                        }
                    }
                }
                finally
                {
                    if (oNs != null)
                    {
                        Marshal.ReleaseComObject(oNs);
                    }
                }

                if (oMapiFolder != null)
                {
                    retVal = _factory.Create <OutlookItem>(oMapiFolder) as OutlookFolder;
                }
            }

            return(retVal);
        }