Reading (Displaying) MailItem with Custom Form

P

Paulem0071

Does anyone have any experience displaying an existing MailItem with a custom
MessageClass?

When I filter and retrieve an affected Mailtem, I get an
DISP_E_MEMBERNOTFOUND exception when calling mailitem.Display(false)

Here is a code excerpt:

string filter = @"@SQL=(""urn:schemas:httpmail:subject"" like '%test%' ";
filter = filter + @" AND
""http://schemas.microsoft.com/mapi/proptag/0x001a001e"" =
'IPM.Note.Special.Note)";

Outlook.Items items = (Outlook.Items)folder.Items.Restrict(filter);

foreach (object o in items)
{

OutlookMailItem f = o as Outlook.MailItem;
//this fails with DISP_E_MEMBERNOTFOUND
f.GetInspector.Display(false);

//so does this
f.Display(false);
//just do one
break;
}

Thanks a lot.
 
K

Ken Slovak - [MVP - Outlook]

Is that a typo with the missing single quote after the name of your custom
MessageClass? Have you checked the returned restricted Items collection to
see if the items.Count property is greater than 0?
 
P

Paulem0071

Yes, that is a typo.

Also, I am getting objects returned.

Is the proper way to display a mail tiem (that is, open it as if you double
clicked on the message in the inbox), Outlook.Mailitem.Display(bool)?

Thank you.
 
K

Ken Slovak - [MVP - Outlook]

Yes, Mailitem.Display(bool) is correct and you really should only use false
as your bool value. Modal Inspectors usually cause various problems.

That error you get (DISP_E_MEMBERNOTFOUND) is usually a C++ type error that
occurs when there are problems with an IDispatch pointer, so I'm not sure
why you'd see it with C# code. It would indicate that there are 0 members
but that can't be if your restricted Items collection's Count property is
greater than 0, or that an attempt to set a read-only property was made.
 

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