PublishForm method fails in C#

S

Stu

Hi all,

I am trying to write a component that will assist in the deployment of a
custom form to the exchange server. I have included my code below, but it is
failing on the
myForm.PublishForm(Microsoft.Office.Interop.Outlook.OlFormRegistry.olPersonalRegistry,
CalendarFolder); line. Has anyone successfully got a C# app to deploy a form
from an .oft file before?

The code:
Microsoft.Office.Interop.Outlook.ApplicationClass myOlApp;
Microsoft.Office.Interop.Outlook._NameSpace olNs;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder;

try
{
string filename = string.Empty;
string strTemp = string.Empty;
int endpos;
int mylength;
myOlApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
olNs = myOlApp.GetNamespace("MAPI");
CalendarFolder =
olNs.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

//retrieve Outlook Templates
System.Reflection.Assembly Asm =
System.Reflection.Assembly.GetExecutingAssembly();
filename = System.IO.Path.GetDirectoryName(Asm.Location) +
@"\IPM.Appointment.Solomon.oft";
if( filename != "")
{
mylength = filename.Length;

//strip off the extension from the filename. This will be the name of the
form.
endpos = filename.IndexOf(".oft");
strTemp = filename.Substring(0, endpos).Trim();

//publish all Outlook forms into the Personal Registry
Microsoft.Office.Interop.Outlook.AppointmentItemClass myItem =
(Microsoft.Office.Interop.Outlook.AppointmentItemClass)
myOlApp.CreateItemFromTemplate(filename, CalendarFolder);
Microsoft.Office.Interop.Outlook.FormDescription myForm =
myItem.FormDescription;

myForm.Name = "Solomon Integrated Appointment";
myForm.PublishForm(Microsoft.Office.Interop.Outlook.OlFormRegistry.olPersonalRegistry, CalendarFolder);

myItem.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
myItem = null;
myForm = null;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
finally
{
myOlApp = null;
olNs = null;
CalendarFolder = null;

GC.Collect();
}
 

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

Similar Threads


Top