I want to publish Custom Forms to the Personal Folder of the outlook based in .oft files. The VB code its very easy, the hardest thing its to pass it to C# because the outlook object library is very tight.
This is the VB original Code:
'Add Project Reference: Microsoft Outlook 11.0 Object Library (mstoul.olb)
Sub PublishFromFile() Dim filename As String Dim Temp As String Dim endpos As Integer Dim mylength As Integer Set myOlApp = GetObject("", "Outlook.Application")
aux=path2 + filename; Folders folder ; //Here is the hard stuff //Create item from template file (.oft) Items myItem = (Items)outLookAPP.CreateItemFromTemplate(aux,folder); //Create a form to publish FormDescription myForm =(FormDescription)myItem.FormDescription; //Assign the name myForm.Name=strTemp.ToString(); //Publish de Form myForm.PublishForm(Outlook.OlFormRegistry.olPersonalRegistry,folder ); }
I dont have compile errors, just a runtime error that sayts : cannot cast object , exactly in this line:
I have tryed different code to publish Contacts, Tasks, etc in Outlook, the problem comes when publishing Custom Forms, I don't know what object to use. I only have Mail, Item, Contact, Task, etc option, but not a Form object.