programmatically set up default form

J

Jason

For Outlook 2003, the solution in the MS article "How to globally change the
default forms in Outlook by using the Forms Administrator utility"
http://support.microsoft.com/kb/241235 only works if the custom form is
published to a folder; it does not work if the form is published into
Personal Form Library.


Question 1: What is the code to publish a form into calendar folder in
Outlook 2003?

The C# code here http://www.outlookcode.com/codedetail.aspx?id=1033 only
publishes the form to Personal Form Library. How to change it for calendar
folder?

I found the code sometime ago. It published the form into calendar folder
but at the same time created an appointment item in the folder. I lost that
code and cannot not retrieve it back.


Question 2: What is correct registry keys for Outlook 2003 when the form is
published into Personal Form Library? The keys below only works when the
form is published into calendar folder.


[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Custom Forms]

[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Custom
Forms\Compose]
"IPM.Appointment"="xxxxx"

[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Custom Forms\Read]
"IPM.Appointment"="xxxxx"
 
K

Ken Slovak - [MVP - Outlook]

When you supply the folder library to the Publish() method just use
OlFormRegistry.olFolderRegistry, then supply the optional Folder argument
with a Calendar folder object.

It only works when published to a folder or the Organizational Forms Library
(with Exchange).
 
J

Jason

Thanks Ken.

Me and another guy tried folder but could not make it work. Got runtime
ComInterop error on publish line:

formDescription.PublishForm(Outlook.OlFormRegistry.olPersonalRegistry,
calendarFolder);

the error message is "One or more parameters are incorrect."

Code:

private void PublishCustomForm()
{
Outlook.Application app = Globals.ThisAddIn.Application;
Outlook.NameSpace ns = app.GetNamespace("MAPI");
Outlook.MAPIFolder calendarFolder =
ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

object missing = System.Reflection.Missing.Value;

// create the item from TemplateFile

//Outlook.AppointmentItem item =
(Outlook.AppointmentItem)app.CreateItemFromTemplate(@"xxx.oft",
calendarFolder);
//Outlook.FormDescription formDescription = item.FormDescription;

object item = app.CreateItemFromTemplate(@"xxx.oft", calendarFolder);
Type itemType = item.GetType();
Outlook.FormDescription formDescription =
(Outlook.FormDescription)itemType.InvokeMember("FormDescription",
System.Reflection.BindingFlags.GetProperty, null, item, null);

// Apply some Parameters to the Formdescription
formDescription.Name = "xxx";

// Publish Form to Personal Froms Library
formDescription.PublishForm(Outlook.OlFormRegistry.olPersonalRegistry,
calendarFolder);
}





Ken Slovak - said:
When you supply the folder library to the Publish() method just use
OlFormRegistry.olFolderRegistry, then supply the optional Folder argument
with a Calendar folder object.

It only works when published to a folder or the Organizational Forms
Library (with Exchange).




Jason said:
For Outlook 2003, the solution in the MS article "How to globally change
the default forms in Outlook by using the Forms Administrator utility"
http://support.microsoft.com/kb/241235 only works if the custom form is
published to a folder; it does not work if the form is published into
Personal Form Library.


Question 1: What is the code to publish a form into calendar folder in
Outlook 2003?

The C# code here http://www.outlookcode.com/codedetail.aspx?id=1033 only
publishes the form to Personal Form Library. How to change it for
calendar folder?

I found the code sometime ago. It published the form into calendar folder
but at the same time created an appointment item in the folder. I lost
that code and cannot not retrieve it back.


Question 2: What is correct registry keys for Outlook 2003 when the form
is published into Personal Form Library? The keys below only works when
the form is published into calendar folder.


[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Custom Forms]

[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Custom
Forms\Compose]
"IPM.Appointment"="xxxxx"

[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Custom
Forms\Read]
"IPM.Appointment"="xxxxx"
 
K

Ken Slovak - [MVP - Outlook]

OlFormRegistry.olFolderRegistry, not OlFormRegistry.olPersonalRegistry.

An error is to be expected if you use the Folder argument and supply the
Personal Forms Library as the first argument.
 
J

Jason

Great. It works. The form was published into calendar folder with no side
effect. However, the custom form did not become default form even the
"custom form" registry keys were there. It does show up in the "when posting
to this folder, use" dropdownlist.

I was wrong. The "custom form" registry keys created by admin tool did not
work, no matter the custom form wsa published manually or programmatically.
Looks like I have to give up and ask user to do it manually.
 
J

Jason

"custom form" registry keys work. It does not matter where the form is
published to, either calanedar folder or personal form library. What
confused me was that the "use" dropdownlist does not change. I guess the
default selection here does not matter because registry key setting
overrides it.

Publish form works. I'd move it to the first run of add-in.

Thank you very much Ken.
 
K

Ken Slovak - [MVP - Outlook]

You'd need to use a different API (lower level) or Outlook 2007 to set that
up correctly.

The properties you need to set would be:

PR_DEF_POST_DISPLAYNAME (0x36E6001E) a PT_STRING8 property to the display
name of the custom form (for example "MyForm").

PR_DEF_POST_MSGCLASS (0x36E5001E) also a PT_STRING8 property to the custom
MessageClass of your form ("IPM.Appointment.MyForm").

Aside from Outlook 2007's PropertyAccessor, you can work with those
properties using CDO 1.21 (no managed code support), Extended MAPI (C++ or
Delphi only, no managed code support) or a MAPI COM wrapper such as
Redemption (www.dimastr.com/redemption).

Setting those properties is the equivalent of setting what you see in the
Properties dialog for the folder in the UI for the "When posting to this
folder, use: " setting.

Setting the following properties is the equivalent of setting the "Forms
associated with the this folder:" property in the Forms tab of the folder
Properties dialog:

PR_ENTERPRISE_FORMS_CN (0x36E7101E) a PT_MV_STRING8 (multivalued string,
which is a string array) to the same custom MessageClass as
PR_DEF_POST_MSGCLASS.

PR_ENTERPRISE_FORMS_DN (0x36E8101E) also a PT_MV_STRING8 (multivalued
string, which is a string array) to the same display name used for
PR_DEF_POST_DISPLAYNAME.
 
Joined
May 16, 2016
Messages
1
Reaction score
0
Hi Ken, I thing i got what you need.It's a sub that does the weirdest of assignments needed for the rigid outlook object model.here comes:

Code:
   void SetFolderDefaultForm_forappointments(Outlook.MAPIFolder fld , string msgClass, string displayname ){
        Outlook.PropertyAccessor objPA = fld.PropertyAccessor;
    string strBaseType ;
    string strMsg ;
    int intLoc ;
    bool blnBadForm;
   int i ;
    string PR_DEF_POST_MSGCLASS =
      "http://schemas.microsoft.com/mapi/proptag/0x36E5001E";
    string PR_DEF_POST_DISPLAYNAME =
      "http://schemas.microsoft.com/mapi/proptag/0x36E6001E";

    string[] arrSchema = { PR_DEF_POST_MSGCLASS, PR_DEF_POST_DISPLAYNAME };
        string[]arrValues ={msgClass, displayname};
        string[] arrErrors;
        if(debugmessages) MessageBox.Show("prepared for setting default item");
        try{
         objPA = fld.PropertyAccessor;
         objPA.SetProperty(PR_DEF_POST_MSGCLASS, msgClass);
         objPA.SetProperty(PR_DEF_POST_DISPLAYNAME, displayname);
         if(debugmessages) MessageBox.Show("default folder set");
      //  arrErrors = objPA.SetProperties(arrSchema, arrValues);
        }
        catch (SystemException sex)
        {
            Console.WriteLine("This is catch with system exception : {0}", sex.ToString());
        }
 
           
    }

you just have to find the which displayname is the name of the calendar. MsgClass(something like IPM.Appointment.xxxxxxx where xxxxxx is the name (not displayname )of the form you have published.You can see the difference in the following publishForm code

Code:
Outlook.FormDescription formDescription = (Outlook.FormDescription)itemType.InvokeMember("FormDescription", System.Reflection.BindingFlags.GetProperty, null, item, null);

    // Apply some Parameters to the Formdescription
    formDescription.Name = name;
    formDescription.DisplayName = displayName;
    formDescription.Category = "uncategorized";
    formDescription.Comment = description;
    formDescription.Version = version;
   
    // Publish Form to Personal Froms Library
      formDescription.PublishForm(Microsoft.Office.Interop.Outlook.OlFormRegistry.olFolderRegistry , calendarfolder);
where calendfolder is a Outlook.MAPIFolder
 

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