Check for empty Explorer.Selection causes error in Outlook Today

  • Thread starter Slava Barouline
  • Start date
S

Slava Barouline

Hi guys

I have an explorer toolbar in my Add-in and when user presses buttons on it,
Add-in does something to a selected mail item.

When I am in Outlook Today, it doesn't work - for unknown reason the check
Assigned(IExplorer.Selection) raises an exception.

IExplorer is not empty.

Why is it so?

Thanks
Slava
 
S

Slava Barouline

I have found an ugly hack

I check if I am in 'Outlook Today' folder:
IExplorer.CurrentFolder.Name <> FOutlookTodayFolder.Name

Strangely
IExplorer.CurrentFolder<> FOutlookTodayFolder
doesn't work for some reason

I get FOutlookTodayFolder like this:

NmSpace := OutlookApp.GetNamespace('MAPI');
Inbox := NmSpace.GetDefaultFolder(olFolderInbox);
FOutlookTodayFolder := Inbox.Parent as MAPIFolder;
 
K

Ken Slovak - [MVP - Outlook]

Selection is probably empty because the OutlookToday folder is the top of
store and usually doesn't have items in it or anything selected.
 
D

Dmitry Streblechenko

You'd be better off comparing the entry ids rather than names.
The fact that (IExplorer.CurrentFolder<> FOutlookTodayFolder) is perfectly
normal. Each time you access Explorer.CurrentFolder, OOM returns a brand new
COM object.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
S

Slava Barouline

In a normal folder Selection is never nil, even if it's empty

When I try to access IExplorer.Selection for Outlook Today, it's not empty -
I get an error
Probably Selection is invalid for Outlook Today
 
S

Slava Barouline

I will probably use EntryID if
(IExplorer.CurrentFolder<>FOutlookTodayFolder) will not work

It shows different addresses for IExplorer.CurrentFolder and
FOutlookTodayFolder
How can I compare them?
 
D

Dmitry Streblechenko

Because nothing prevents a user from creating a folder with the same name
somewhere else in the folder hierarchy. The folder name will be different in
a locale other than English.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
T

t.rokohl

a easier way to check it is:

int selected_items
try
{
selected_items = _Explorer.Selection.Count;
}
catch (COMException e)
{
return;
}


;-)

greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top