Custom Message forms, Outlook2003, C#

K

Krishna

Outlook 2003, Custom forms, C#.
I have a custom message form, published into Personal Outlook Folders.
I want to use the form whenever I open an email. The message remains in
Inbox and I don't have any custom folder for which my custom form is
the default form. In the mail-item-open event handler, I am setting the
mesasgeclass to my custom form class. But, I get the default form only.
OutlookSpy shows the mesasgeclass is IPM.Note. If I change the filed
manually in OutlookSpy and save the changes, close outlook and re-open,
I get the custom form.
I tried accessing PR_MESSAGE_CLASS in C# using CDO, but I am unable to
do so. Is there any documentation for C# version of CDO1.21.
I cannot save the mail-item because I want to use the custom-form only
to display the message and when user closes the form, I need to store
the message with default form and original message-body. (In the
mail-item-open event handler, I change the message-body
programmatically.)
My code snippet is as follows:
private void myMailItem_Open(ref bool Cancel)
{
if (myMailItem.SenderEmailAddress != null)
{
myMailItem.MessageClass = "IPM.Note.MyNewMailForm";

myMailItem.HTMLBody = " this should be a custom form.";
}
.....
}
my other approach:
private void myMailItem_Open(ref bool Cancel)
{
if (myMailItem.SenderEmailAddress != null)
{
// trying to access PR_MESSAGE_CLASS.

CDO.SessionClass newSession = new CDO.SessionClass();
newSession.MAPIOBJECT =
MailItem.Application.Session.MAPIOBJECT;
CDO.Message newMsg =
CDO.Message)newSession.GetMessage(myMailItem.EntryID, myMissing);
CDO.Fields oFields = (CDO.Fields)newMsg.Fields;
int idx = 0;
oFields.get_Item(idx,
CDO.CdoPropTags.CdoPR_MESSAGE_CLASS);


}
....
}


For me, the GetMesage(..) itself is failing. Also, I could not find the
docuementation for C#, CDO1.21. I coudldn't figure out the first
argument, 'object index' for Fileds.get_Item(..).

Any suggestion/help would be of great help.

Thanks,
Krishna.
 
K

Ken Slovak - [MVP - Outlook]

There is no documentation for C# and CDO 1.21 because CDO is not supported
for use in .NET code. It might work, some things might work or it might work
almost all the time, but it's not supported. You're on your own.
 
K

Krishna

Thanks for the info. I was able to get to PR_MESSAGE_CLASS and set it
to my custom form class. I thought that if I set PR_MESSAGE_CLASS, I
would get the custom form, but I still do not get the custom form. Am I
missing something here?
 
K

Ken Slovak - [MVP - Outlook]

What you change in CDO is not something that Outlook would know about until
you save the change and get Outlook to refresh. That usually involves
closing an item and re-opening it.

Why not just use Outlook object model code to change the MessageClass?
Outlook would know about that right away.
 
K

Krishna

I thought I should take the CDO route because Outlook Object Model is
not showing the custom-form if i change the MessageClass in
mail-item-open event handler. Although I was able to set
PR_MESSAGE_CLASS using CDO, it was of no use. It required saving and
re-opening the mail-item as you told.

Using Outlook Object Model, if i change the MessageClass in new-mail
event handler, and save the mail-item, then release it and call garbage
collector so that the mail-item variable i used is removed, i am
getting the custom form when i open that mail-item.

{
....
// new-mail event handler:
Ol.MailItem mi =
(Ol.MailItem)(applicationObject.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Items.GetLast());

mi.MessageClass = "IPM.Note.MyNewMailForm";
mi.Save();
Marshal.ReleaseComObject(mi);
GC.Collect();
GC.WaitForPendingFinalizers();
}

1. I don't want to save the mail-item with the MessageClass
modified.(if that is not possible, i can live with that)
2. i need to modify the mail-item body and display it in the custom
form, and when i close the custom form, i should get back the original
messagebody. i can acchive this by keeping track of the mesasgebody,
which is trivial, but i don't want to modify the mail-item in outlook.
i want to make a copy of the mail-item and display it in custom-form.
using OOM, i am unable to assign to CurrentItem of Inspector!

Can you suggest me something.

Thanks,
Krishna.
 
K

Ken Slovak - [MVP - Outlook]

Inspector.CurrentItem is read-only, look at that property in the Object
Browser. That's why you can't set it. If you want to display a copy you
would have to use Item.GetInspector and use the Inspector's Display method.
You can do that and save and close the original item, then update the
original as desired and re-open it.

Of course that will cause display flashes as one item is opened and another
is closed then re-opened.

There's no Refresh method to force the Inspector to refresh or to force an
Outlook item to refresh itself if changes are made to it using MAPI or CDO
or Redemption. Those are API's that Outlook doesn't monitor. We use a
workaround to force an Outlook item to refresh:

oItem.Subject = oItem.Subject;

That makes Outlook refresh itself and the item is updated with any changes
made using a different API.

I think what I would do is possibly re-think the architecture to see an
alternative can be used. Or you can live with Outlook's limitations.
 

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