/// <summary>
        /// Creates a new custom calendar in Outlook (if it does not exist yet)
        /// </summary>
        public void CreateCustomCalendar()
        {
            if (_customCalendar != null)
            {
                return;
            }

            try
            {
                // create new calendar
                _customCalendar = _primaryCalendar.Folders.Add(_calendarName, Outlook.OlDefaultFolders.olFolderCalendar);

                // add the new custom calendar to the navigation panel
                Outlook.NavigationPane   objPane      = _outlookApp.ActiveExplorer().NavigationPane;
                Outlook.CalendarModule   objModule    = (Outlook.CalendarModule)objPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar);
                Outlook.NavigationGroup  objGroup     = objModule.NavigationGroups.GetDefaultNavigationGroup(Outlook.OlGroupType.olMyFoldersGroup);
                Outlook.NavigationFolder objNavFolder = objGroup.NavigationFolders.Add(_customCalendar);

                // Set the navigation folder to be displayed in overlay mode by default
                objPane.CurrentModule = objPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar);

                if (objPane.CurrentModule == objPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar))
                {
                    // The IsSelected property can't be set to True unless the CalendarModule object is the current module displayed in the Navigation Pane
                    objNavFolder.IsSelected   = true;
                    objNavFolder.IsSideBySide = false;
                }

                SetEvents();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The following error occurred: " + ex.Message);
            }
        }
Exemplo n.º 2
0
        // OnMyButtonClick routine handles all button click events
        // and displays IRibbonControl.Context in message box
        public void OnMyButtonClick(Office.IRibbonControl control)
        {
            string msg = string.Empty;

            if (control.Context is Outlook.AttachmentSelection)
            {
                msg = "Context=AttachmentSelection" + "\n";
                Outlook.AttachmentSelection attachSel =
                    control.Context as Outlook.AttachmentSelection;
                foreach (Outlook.Attachment attach in attachSel)
                {
                    msg = msg + attach.DisplayName + "\n";
                }
            }
            else if (control.Context is Outlook.Folder)
            {
                msg = "Context=Folder" + "\n";
                Outlook.Folder folder =
                    control.Context as Outlook.Folder;
                msg = msg + folder.Name;
            }
            else if (control.Context is Outlook.Selection)
            {
                msg = "Context=Selection" + "\n";
                Outlook.Selection selection =
                    control.Context as Outlook.Selection;
                if (selection.Count == 1)
                {
                    OutlookItem olItem =
                        new OutlookItem(selection[1]);
                    msg = msg + olItem.Subject
                          + "\n" + olItem.LastModificationTime;
                }
                else
                {
                    msg = msg + "Multiple Selection Count="
                          + selection.Count;
                }
            }
            else if (control.Context is Outlook.OutlookBarShortcut)
            {
                msg = "Context=OutlookBarShortcut" + "\n";
                Outlook.OutlookBarShortcut shortcut =
                    control.Context as Outlook.OutlookBarShortcut;
                msg = msg + shortcut.Name;
            }
            else if (control.Context is Outlook.Store)
            {
                msg = "Context=Store" + "\n";
                Outlook.Store store =
                    control.Context as Outlook.Store;
                msg = msg + store.DisplayName;
            }
            else if (control.Context is Outlook.View)
            {
                msg = "Context=View" + "\n";
                Outlook.View view =
                    control.Context as Outlook.View;
                msg = msg + view.Name;
            }
            else if (control.Context is Outlook.Inspector)
            {
                msg = "Context=Inspector" + "\n";
                Outlook.Inspector insp =
                    control.Context as Outlook.Inspector;
                if (insp.AttachmentSelection.Count >= 1)
                {
                    Outlook.AttachmentSelection attachSel =
                        insp.AttachmentSelection;
                    foreach (Outlook.Attachment attach in attachSel)
                    {
                        msg = msg + attach.DisplayName + "\n";
                    }
                }
                else
                {
                    OutlookItem olItem =
                        new OutlookItem(insp.CurrentItem);
                    msg = msg + olItem.Subject;
                }
            }
            else if (control.Context is Outlook.Explorer)
            {
                msg = "Context=Explorer" + "\n";
                Outlook.Explorer explorer =
                    control.Context as Outlook.Explorer;
                if (explorer.AttachmentSelection.Count >= 1)
                {
                    Outlook.AttachmentSelection attachSel =
                        explorer.AttachmentSelection;
                    foreach (Outlook.Attachment attach in attachSel)
                    {
                        msg = msg + attach.DisplayName + "\n";
                    }
                }
                else
                {
                    Outlook.Selection selection =
                        explorer.Selection;
                    if (selection.Count == 1)
                    {
                        OutlookItem olItem =
                            new OutlookItem(selection[1]);
                        msg = msg + olItem.Subject
                              + "\n" + olItem.LastModificationTime;
                    }
                    else
                    {
                        msg = msg + "Multiple Selection Count="
                              + selection.Count;
                    }
                }
            }
            else if (control.Context is Outlook.NavigationGroup)
            {
                msg = "Context=NavigationGroup" + "\n";
                Outlook.NavigationGroup navGroup =
                    control.Context as Outlook.NavigationGroup;
                msg = msg + navGroup.Name;
            }
            else if (control.Context is
                     Microsoft.Office.Core.IMsoContactCard)
            {
                msg = "Context=IMsoContactCard" + "\n";
                Office.IMsoContactCard card =
                    control.Context as Office.IMsoContactCard;
                if (card.AddressType ==
                    Office.MsoContactCardAddressType.
                    msoContactCardAddressTypeOutlook)
                {
                    // IMSOContactCard.Address is AddressEntry.ID
                    Outlook.AddressEntry addr =
                        Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(
                            card.Address);
                    if (addr != null)
                    {
                        msg = msg + addr.Name;
                    }
                }
            }
            else if (control.Context is Outlook.NavigationModule)
            {
                msg = "Context=NavigationModule";
            }
            else if (control.Context == null)
            {
                msg = "Context=Null";
            }
            else
            {
                msg = "Context=Unknown";
            }
            MessageBox.Show(msg,
                            "RibbonXOutlook14AddinCS",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }