Event for folders changing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have googled around a bit and haven't found what I need.
I am coding in C#, not VB.

Outlook 2002 and above.
I have some New Mail, Reply buttons. I only want to enable these at the
same time Outlook enables the proper ones.

So if they change folders to Today or Calendar, I would like to remove the
buttons I have added.

I can't figure out which event I should be registering for?
And, assuming an event, which property should I check to determine if:
1. I am viewing mail items
2. One is selected (otherwise I want to disable Reply)
3. If the Calendar has been selected
4. If Notes are active, since I will also want to do something similar with
Notes.

Looking for some examples, so if you are aware of any code snippets (VB if
C# note available) that do this kind of thing, point them out to me.

Much appreciated.
Dave
 
This is for an Explorer window (folder view) only?

Use ActiveExplorer.CurrentFolder to determine what folder is being displayed
and what type it is.

Outlook.MAPIFolder folder = (Outlook.MAPIFolder)
appOL.ActiveExplorer().CurrentFolder;

if(folder.DefaultItemType == OlItemType.olMailItem)
{
// it's a mail folder

// for a calendar folder
// if folder.DefaultItemType == OlItemType.olAppointmentItem
}

int itemsSelected = folder.Selection.Count;

Don't try to do much with Notes, they're brain dead. Never, ever try to add
a UI to an open Note Inspector.

The event to register for is Explorer.CommandBars.OnUpdate(). The
ActiveExplorer() is the one you want to use. However, that's an expensive
event to handle, it fires all the time. It also fires multiple times for
just one change and when buttons are being disabled you can expect it to
fire many times.

That event passes no in arguments so you will have to monitor certain
CommandBarButton objects to check their Enabled state. The CommandBar
objects are in the Office tlb.

You also have to be aware that there is no deterministic way to know when
your handler for the event will fire relative to when the buttons such as
Reply are disabled. You will have to test for that and possibly handle a few
test cases.
 
Back
Top