PC Review


Reply
Thread Tools Rate Thread

Addin loading custom outlook forms by default

 
 
sublimese
Guest
Posts: n/a
 
      12th Jan 2005
I am writing an Addin for Outlook 2003 using C#. I am wondering if
anyone can answer a question or point me in the proper direction.

When my addin loads in Outlook, I want custom Outlook forms to be used
instead of the default Outlook forms. For example, when someone goes
to their inbox and opens an email (or presses the "New" button to make
an new email), when my addin is loaded, I want Outlook to load
"IPM.Email.MyCustomEmail", when/if my addin is not loaded, I would want
Outlook to load its default form. Is there a way to do this? I have
looked into trying to iterate the folders collection and setting the
default message type (which does not work because that property is read
only). The ideal solution would be to hook the form opening event in
my addin and have it open my custom form and cancel the opening of the
default form. If the ideal solution is not possible, dynamically
setting the MessageType on each folder would work as well.
Thank you very much,
Kelly Johnson

 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      12th Jan 2005
Some basic Outlook principles and thoughts on how they might affect your
project:

1) You cannot set a message form as the default form for a folder. It would
be meaningless, since messages are designed to be sent, not saved.

2) Changing the default form for a folder has no effect on existing items.
(Remember that Outlook is a semi-structured database and allows
heterogeneous items in a single folder.)

3) You can make a registry change to substitute your custom form for the
default form. See
http://www.outlookcode.com/d/newdefa...#changedefault . However, it
doesn't work completely for message forms in Outlook 2003 and so this method
would probably not be suitable.

4) To change the form used for an individual item, you need to change the
MessageClass of that item. This can be tricky when you're doing it on the
fly. In your case, you could use the NewInspector event to detect the item
opening, change the MessageClass, save the item, get its EntryID, and then
close the Inspector and dereference all objects. Then use
Namespace.GetItemFromID to open the item, hopefully displaying the custom
form. Because of Outlook's caching and .NET's garbage collection, I'm not
sure it will work, though.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"sublimese" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am writing an Addin for Outlook 2003 using C#. I am wondering if
> anyone can answer a question or point me in the proper direction.
>
> When my addin loads in Outlook, I want custom Outlook forms to be used
> instead of the default Outlook forms. For example, when someone goes
> to their inbox and opens an email (or presses the "New" button to make
> an new email), when my addin is loaded, I want Outlook to load
> "IPM.Email.MyCustomEmail", when/if my addin is not loaded, I would want
> Outlook to load its default form. Is there a way to do this? I have
> looked into trying to iterate the folders collection and setting the
> default message type (which does not work because that property is read
> only). The ideal solution would be to hook the form opening event in
> my addin and have it open my custom form and cancel the opening of the
> default form. If the ideal solution is not possible, dynamically
> setting the MessageType on each folder would work as well.
> Thank you very much,
> Kelly Johnson
>



 
Reply With Quote
 
sublimese
Guest
Posts: n/a
 
      20th Jan 2005
Thank you very much for your reply.

Kelly Johnson

Sue Mosher [MVP-Outlook] wrote:
> Some basic Outlook principles and thoughts on how they might affect

your
> project:
>
> 1) You cannot set a message form as the default form for a folder. It

would
> be meaningless, since messages are designed to be sent, not saved.
>
> 2) Changing the default form for a folder has no effect on existing

items.
> (Remember that Outlook is a semi-structured database and allows
> heterogeneous items in a single folder.)
>
> 3) You can make a registry change to substitute your custom form for

the
> default form. See
> http://www.outlookcode.com/d/newdefa...#changedefault .

However, it
> doesn't work completely for message forms in Outlook 2003 and so this

method
> would probably not be suitable.
>
> 4) To change the form used for an individual item, you need to change

the
> MessageClass of that item. This can be tricky when you're doing it on

the
> fly. In your case, you could use the NewInspector event to detect the

item
> opening, change the MessageClass, save the item, get its EntryID, and

then
> close the Inspector and dereference all objects. Then use
> Namespace.GetItemFromID to open the item, hopefully displaying the

custom
> form. Because of Outlook's caching and .NET's garbage collection, I'm

not
> sure it will work, though.
>
> --
> Sue Mosher, Outlook MVP
> Author of
> Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
> "sublimese" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I am writing an Addin for Outlook 2003 using C#. I am wondering if
> > anyone can answer a question or point me in the proper direction.
> >
> > When my addin loads in Outlook, I want custom Outlook forms to be

used
> > instead of the default Outlook forms. For example, when someone

goes
> > to their inbox and opens an email (or presses the "New" button to

make
> > an new email), when my addin is loaded, I want Outlook to load
> > "IPM.Email.MyCustomEmail", when/if my addin is not loaded, I would

want
> > Outlook to load its default form. Is there a way to do this? I

have
> > looked into trying to iterate the folders collection and setting

the
> > default message type (which does not work because that property is

read
> > only). The ideal solution would be to hook the form opening event

in
> > my addin and have it open my custom form and cancel the opening of

the
> > default form. If the ideal solution is not possible, dynamically
> > setting the MessageType on each folder would work as well.
> > Thank you very much,
> > Kelly Johnson
> >


 
Reply With Quote
 
sublimese
Guest
Posts: n/a
 
      24th Jan 2005
I am following one of your suggestions (using newinspector, changing
the messageclass, saving the item, getting its entryID, closing the
inspector, then using GetItemFromID to open the item), however I
encounter the error "Cannot Display Item" when I call item.Display();
(getItemFromID does not error, but seems to return a blank item) The
item in question, does have its MessageClass changed, and if I manually
open the item after my code has run, the item opens in my custom form.
When the following code is run, the messageclass is successfully
changed, however an error occurs when trying to run item.Display(false)
(the error is "Cannot Display Item") AND the inspector referenced in
"NewInspector" displays anyway. Any ideas of what I am doing wrong?

private void OnNewInspector(Microsoft.Office.Interop.Outlook.Inspector
oInspect)
{
Microsoft.Office.Interop.Outlook.ContactItem oCont =
(Microsoft.Office.Interop.Outlook.ContactItem)oInspect.CurrentItem;
oCont.MessageClass = "IPM.Contact.Test1";
oCont.Save();
string entryID = oCont.EntryID;
oCont.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCont);

oInspect.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);

Microsoft.Office.Interop.Outlook.ContactItem newItem = null;
newItem =
(Microsoft.Office.Interop.Outlook.ContactItem)applicationObject.GetNamespace("MAPI").GetItemFromID(entryID,
System.Type.Missing);
newItem.Display(false);
}

The item that I am opeing for testing starts as a normal contact
(IPM.Contact)

I have done a couple of variations of GetItemFromID:
object storeID;
Microsoft.Office.Interop.Outlook.MAPIFolder oParent;
oParent = (Microsoft.Office.Interop.Outlook.MAPIFolder)oCont.Parent;
storeID = oParent.StoreID;
....
newItem =
(Microsoft.Office.Interop.Outlook.ContactItem)applicationObject.GetNamespace("MAPI").GetItemFromID(entryID,
storeID);
newItem.Display(false);
//this gives the same "Cannot Display Item" error message
Thank you for any help you can provide.
Kelly Johnson

 
Reply With Quote
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      24th Jan 2005
I'm not that familiar with C#, but don't you also need to use:

oCont = null;

to finish the process of removing all references to oCont before you invoke
GetItemFromID?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"sublimese" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am following one of your suggestions (using newinspector, changing
> the messageclass, saving the item, getting its entryID, closing the
> inspector, then using GetItemFromID to open the item), however I
> encounter the error "Cannot Display Item" when I call item.Display();
> (getItemFromID does not error, but seems to return a blank item) The
> item in question, does have its MessageClass changed, and if I manually
> open the item after my code has run, the item opens in my custom form.
> When the following code is run, the messageclass is successfully
> changed, however an error occurs when trying to run item.Display(false)
> (the error is "Cannot Display Item") AND the inspector referenced in
> "NewInspector" displays anyway. Any ideas of what I am doing wrong?
>
> private void OnNewInspector(Microsoft.Office.Interop.Outlook.Inspector
> oInspect)
> {
> Microsoft.Office.Interop.Outlook.ContactItem oCont =
> (Microsoft.Office.Interop.Outlook.ContactItem)oInspect.CurrentItem;
> oCont.MessageClass = "IPM.Contact.Test1";
> oCont.Save();
> string entryID = oCont.EntryID;
> oCont.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);
> System.Runtime.InteropServices.Marshal.ReleaseComObject(oCont);
>
> oInspect.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
>
> Microsoft.Office.Interop.Outlook.ContactItem newItem = null;
> newItem =
> (Microsoft.Office.Interop.Outlook.ContactItem)applicationObject.GetNamespace("MAPI").GetItemFromID(entryID,
> System.Type.Missing);
> newItem.Display(false);
> }
>
> The item that I am opeing for testing starts as a normal contact
> (IPM.Contact)
>
> I have done a couple of variations of GetItemFromID:
> object storeID;
> Microsoft.Office.Interop.Outlook.MAPIFolder oParent;
> oParent = (Microsoft.Office.Interop.Outlook.MAPIFolder)oCont.Parent;
> storeID = oParent.StoreID;
> ...
> newItem =
> (Microsoft.Office.Interop.Outlook.ContactItem)applicationObject.GetNamespace("MAPI").GetItemFromID(entryID,
> storeID);
> newItem.Display(false);
> //this gives the same "Cannot Display Item" error message
> Thank you for any help you can provide.
> Kelly Johnson
>



 
Reply With Quote
 
sublimese
Guest
Posts: n/a
 
      24th Jan 2005
I changed the following lines from:

oCont.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCont);
oInspect.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
Microsoft.Office.Interop.Outlook.ContactItem newItem = null;

To:

oCont.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCont);
oInspect.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oInspect);
oCont = null;
oInspect = null;
Microsoft.Office.Interop.Outlook.ContactItem newItem = null;

This did not change the observed behavior. getItemFromID does not
error (but seems to return a blank item, like a shell, if I try to get
any of the properties of the object from the debugger, I get "xxxx
property does not exist", where xxxx is whatever property I tried to
get.)

My code seems to be getting correct values for EntryID and StoreID
(using Outlook spy to compare values).

This is interesting and is at least partially relevant. I change my
custom form (IPM.Contact.Test1) to display a message box when it
closes. the message box doesn't say or do anything important, it just
says "closing". What is interesting, is that when
"oInspect.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);"
is hit in my code, the messagebox I just added to the form is fired.
This indicates to me that the form is closing. However, when my code
has completed running, the form ends up being displayed. (the form
associated with the inspector referenced by "onNewInspector", not the
form I am trying to open with "getItemFromID and Display", which errors)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook addin not loading TheCommedian Microsoft Outlook Program Addins 2 4th Aug 2008 03:03 PM
Outlook-Addin is not loading =?Utf-8?B?QXR1bFN1cmVrYQ==?= Microsoft Outlook Form Programming 0 3rd Aug 2006 02:53 PM
Opening custom forms on workstation displays Outlook 2003 default =?Utf-8?B?TmVpbCBEaXR0bWFy?= Microsoft Outlook Form Programming 1 6th Jan 2006 06:00 PM
Hiding default Outlook menus when displaying custom forms Long Nguyen Microsoft Outlook Form Programming 3 27th Jul 2005 12:31 PM
loading a form in outlook addin edo Microsoft Outlook Program Addins 2 13th Jun 2004 07:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:09 AM.