Type of Outlook Item

P

PIT

Hi,

is there a way to know which type of item is in a Folder? Also mail,
document or post.

I use c#.

Thanks for tip.

PIT
 
P

Peter Huang [MSFT]

Hi

We can use reflection as below.
The item's Class property will be one of the enum type Outlook.OlItemType.

private void button1_Click(object sender, System.EventArgs e)
{
Outlook.Application olApp = new Outlook.ApplicationClass();
Outlook.MAPIFolder mi =
olApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolde
rInbox);
foreach (Outlook.MAPIFolder o in mi.Folders )
{
if (o.Name=="test" )
{
mi = o;
break;
}
}
foreach(object o in mi.Items)
{
Outlook.OlItemType oo
=(Outlook.OlItemType)o.GetType().InvokeMember("Class",System.Reflection.Bind
ingFlags.GetProperty,null,o,new object[]{});
Console.WriteLine(oo.ToString());
}
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

PIT

Hi Peter,

thanks for your answer. I have found another way:

Outlook._PostItem oP = oo as Outlook._PostItem;
if(oP!=null) {....}
else
{
Outlook._MailItem oM = oo as Outlook._MailItem;
if(oM!=null) {....}
}

which if these way has better performance. I must loop along items?

Regards

PIT
 
P

Peter Huang [MSFT]

Hi

Yes, that is an alternative too.
I guess we just need to call InvokeMember on Certain Item one time.

And then use a switch statement to cast the item to certain type directly.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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