我开发了一个ms-outlook插件似乎可以在我开发它的电脑上工作。但是当这个插件的安装项目在具有ms-office更新版本的机器上运行时,2010年addin_startup事件中的两个过程似乎被忽略,好像光标永远不会通过它们。这两个过程用于发布一个表单并将扩展与表格'相关联。预约日历'默认项目
这里是addin_startup中的大部分代码和两个过程的完整代码
// code in start_up
Outlook.MAPIFolder primaryCalendar = (Outlook.MAPIFolder) this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder personalCalendar = primaryCalendar.Folders.Add(newCalendarName,Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder setcalendar = primaryCalendar.Folders[newCalendarName];
PublishFormToPersonalFormsLibrary(setcalendar,outlookformpathandfilename, registryname, registryname, registryname, registryname + "version 1.0.0.1", "1.0.0.1", Application);
SetFolderDefaultForm_forappointments(setcalendar, "IPM.Appointment." + registryname, newCalendarName);
// first procedure
public void PublishFormToPersonalFormsLibrary(Outlook.MAPIFolder calendarfolder,string oftFilePath, string messageClass, string name, string displayName, string description, string version, Outlook.Application application)
{
object missing = System.Reflection.Missing.Value;
string existingVersion = "";
// try to create an existing Instance of the Form to check the current installed Version
try
{
// create atemplatefolder object
Outlook.MAPIFolder templateFolder = application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts);
// we add our new object here
object existingItem = templateFolder.Items.Add(messageClass);
// did we installed the form
if (existingItem != null)
{
// yes, we did it before
// get the formdescription with latebinding
Type existingItemType = existingItem.GetType();
Outlook.FormDescription existingFormDescription = (Outlook.FormDescription)existingItemType.InvokeMember("FormDescription", System.Reflection.BindingFlags.GetProperty, null, existingItem, null);
// get the installed version
existingVersion = existingFormDescription.Version;
// discard the temporary item
object[] args = { Outlook.OlInspectorClose.olDiscard };
existingItemType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod , null, existingItem, args);
}
}
catch (System.Exception ex)
{
}
// if the existing Version is equal, no need for publishing the form
if (version == existingVersion) return;
// check, if the templatefile exists
if (!System.IO.File.Exists(oftFilePath)) throw new System.IO.FileNotFoundException("Form template could not be found!", oftFilePath);
// create the item from TemplateFile
object item = application.CreateItemFromTemplate(oftFilePath, missing);
// get the FormDescription Property using LateBinding
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 = 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.olPersonalRegistry );
formDescription.PublishForm(Microsoft.Office.Interop.Outlook.OlFormRegistry.olFolderRegistry , calendarfolder);
}
//and also second procedure
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;
try{
objPA = fld.PropertyAccessor;
objPA.SetProperty(PR_DEF_POST_MSGCLASS, msgClass);
objPA.SetProperty(PR_DEF_POST_DISPLAYNAME, displayname);
// arrErrors = objPA.SetProperties(arrSchema, arrValues);
}
catch (SystemException sex)
{
Console.WriteLine("This is catch with system exception : {0}", sex.ToString());
}
}
如何升级我的加载项,以便在2013年和2016年的办公室运行它。如果我试图找到一个c#2016 addin项目怎么办?这适用于vsto 2010吗?或者,是否有人知道ms-outlook 2013,2016中的新内容可能会导致设置不安装插件,特别是两个程序?