none
Explorer.CurrentView causes an error when casting to Outlook.View when you click on Outlook Today and also the RSS Feeds folder RRS feed

  • Question

  • Outlook 2010 Plug-In, the code below is hooked up to explorer folder switch event from thisaddin_startup:

    explorer.FolderSwitch += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_FolderSwitchEventHandler(explorer_FolderSwitch);
                        

    Is the Outlook Today and the RSS Feeds Folder some other type of view?  if so what type of item is that?

     I see that explorer.CurrentView returns 'dynamic', but apparently it is not a Outlook.View.

    I also tried this and it caused the same error:

    if (explorer.CurrentView is Outlook.View)
                                    {

                                    }                   

         Outlook.Explorer explorer = Globals.ThisAddIn.Application.Session.Application.ActiveExplorer();
    
    
                            Outlook.Folder DefaultFolder = (Outlook.Folder)explorer.CurrentFolder;
    
                            switch (DefaultFolder.DefaultItemType)
                            {
                                case Outlook.OlItemType.olMailItem:
                                case Outlook.OlItemType.olContactItem:
                                case Outlook.OlItemType.olDistributionListItem:
                                case Outlook.OlItemType.olTaskItem:
                                case Outlook.OlItemType.olPostItem:
                                case Outlook.OlItemType.olAppointmentItem:
    
                                    Outlook.Views views = explorer.CurrentFolder.Views;
    
    
                                    Outlook.View currentView = null;
    
                                    try
                                    {
       // THE ERROR IS HERE "Operation Failed"
                                        currentView = (Outlook.View)explorer.CurrentView;
                                    }
                                    catch (Exception ex)
                                    {
    					// nooooo! 
                                    }
    
                                    if (currentView != null)
                                    {
                                        // Save the current view 
                                        if (currentView.Name == "Friday Filter")
                                        {
                                            // doing something
                                        }
                                        else
                                        {
                                            // doing something else
                                        }
                                    }
                                    else
                                    {
                                        // doing something else 
                                    }
    
    
                                    break;
                            }

    Friday, April 12, 2013 8:20 PM

Answers

  • I tried getting the currentView from the Folder "explorer.CurrentFolder" instead of the Explorer " (Outlook.View)explorer.CurrentView" and that is working without the Error!

    currentView = DefaultFolder.CurrentView;

    here is the updated code just in case this helps someone:

    Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
    
                            if (explorer == null)
                            {
                                return;
                            }
    
                            // get a refrence to the current folder
                            Outlook.Folder DefaultFolder = (Outlook.Folder)explorer.CurrentFolder;                                                                 
    
                            switch (DefaultFolder.DefaultItemType)
                            {
                                case Outlook.OlItemType.olMailItem:
                                case Outlook.OlItemType.olContactItem:
                                case Outlook.OlItemType.olDistributionListItem:
                                case Outlook.OlItemType.olTaskItem:
                                case Outlook.OlItemType.olPostItem:
                                case Outlook.OlItemType.olAppointmentItem:
    
                                    Outlook.View currentView = null;
    
                                    if (DefaultFolder.CurrentView is Outlook.View)
                                    {
                                        currentView = DefaultFolder.CurrentView;
    
                                        if (currentView != null)
                                        {
                                            // Save the current view 
                                            if (currentView.Name == "Friday Filter")
                                            {
                                                Globals.Ribbons.MondayRibbon.tgbFilterSingleFolder.Checked = true;
                                            }
                                            else
                                            {
                                                Globals.Ribbons.MondayRibbon.tgbFilterSingleFolder.Checked = false;
                                            }
                                        }
                                        else
                                        {
                                            Globals.Ribbons.MondayRibbon.tgbFilterSingleFolder.Checked = false;
                                        }
                                    }                                 
    
                                    break;
                            }

    • Marked as answer by Nerds Tuesday, April 16, 2013 3:09 PM
    Tuesday, April 16, 2013 3:09 PM

All replies

  • what if you change

    Outlook.Explorer explorer = Globals.ThisAddIn.Application.Session.Application.ActiveExplorer();
    //To
    Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();

    have you tried to get the error message?

    with regards, Yuri

    Tuesday, April 16, 2013 1:13 PM
  • I tried getting the currentView from the Folder "explorer.CurrentFolder" instead of the Explorer " (Outlook.View)explorer.CurrentView" and that is working without the Error!

    currentView = DefaultFolder.CurrentView;

    here is the updated code just in case this helps someone:

    Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
    
                            if (explorer == null)
                            {
                                return;
                            }
    
                            // get a refrence to the current folder
                            Outlook.Folder DefaultFolder = (Outlook.Folder)explorer.CurrentFolder;                                                                 
    
                            switch (DefaultFolder.DefaultItemType)
                            {
                                case Outlook.OlItemType.olMailItem:
                                case Outlook.OlItemType.olContactItem:
                                case Outlook.OlItemType.olDistributionListItem:
                                case Outlook.OlItemType.olTaskItem:
                                case Outlook.OlItemType.olPostItem:
                                case Outlook.OlItemType.olAppointmentItem:
    
                                    Outlook.View currentView = null;
    
                                    if (DefaultFolder.CurrentView is Outlook.View)
                                    {
                                        currentView = DefaultFolder.CurrentView;
    
                                        if (currentView != null)
                                        {
                                            // Save the current view 
                                            if (currentView.Name == "Friday Filter")
                                            {
                                                Globals.Ribbons.MondayRibbon.tgbFilterSingleFolder.Checked = true;
                                            }
                                            else
                                            {
                                                Globals.Ribbons.MondayRibbon.tgbFilterSingleFolder.Checked = false;
                                            }
                                        }
                                        else
                                        {
                                            Globals.Ribbons.MondayRibbon.tgbFilterSingleFolder.Checked = false;
                                        }
                                    }                                 
    
                                    break;
                            }

    • Marked as answer by Nerds Tuesday, April 16, 2013 3:09 PM
    Tuesday, April 16, 2013 3:09 PM