Ari*_*el 6 c# outlook-addin outlook-2016
我为选定的附件创建了一个Outlook插件,以获取附件的详细信息.它在Outlook 2010中运行良好.但是当我为Outlook 2016构建它时,它变为null.
以下是ThisAddIn.cs中的代码: -
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
System.Reflection.Assembly assemblyInfo = System.Reflection.Assembly.GetExecutingAssembly();
Uri uriCodeBase = new Uri(assemblyInfo.CodeBase);
string Location = Path.GetDirectoryName(uriCodeBase.LocalPath.ToString());
var path = Location.Split(new string[] { "bin" }, StringSplitOptions.RemoveEmptyEntries);
var rootDir = path[0].ToString();
var forPermissionsRootDirectory = Path.GetDirectoryName(rootDir);
SetPermissions(forPermissionsRootDirectory);
app = this.Application;
app.AttachmentContextMenuDisplay += new Outlook.ApplicationEvents_11_AttachmentContextMenuDisplayEventHandler(app_AttachmentContextMenuDisplay);//attach Attachment context Menu Event//
}
void app_AttachmentContextMenuDisplay(Office.CommandBar CommandBar, Outlook.AttachmentSelection selection)
{
selectedAttachment = selection;
RibbonUI.InvalidateControlMso("ContextMenuAttachments");//will get XML file data//
}
Run Code Online (Sandbox Code Playgroud)
这是AttachmentContextMenu.cs中的代码: -
public void OnOpenMyMotionCalendarButtonClick(Office.IRibbonControl control)
{
Outlook.AttachmentSelection selection = ThisAddIn.selectedAttachment;
if ((selection.Count > 0))
{
//My further working
}
}
Run Code Online (Sandbox Code Playgroud)
在选择中,Outlook 2016总是空的.请建议做什么?
亲切的问候,阿里尔
我相信 Outlook 开发人员添加了额外的逻辑来释放作为参数对象(附件)传递的内容。因此,您需要在事件处理程序中收集所有必需的信息,因为一旦方法结束,对象就会被销毁。没有人可以保证对象在事件处理程序被触发后仍然存在。你在中得到一个有效的对象吗?AttachmentContextMenuDisplay?
所有 Outlook 加载项都应在不再需要时系统地释放对 Outlook 对象的引用。使用完 Outlook 对象后,使用System.Runtime.InteropServices.Marshal.ReleaseComObject释放该对象。然后将变量设置为 Visual Basic 中的 Nothing(C# 中的 null)以释放对该对象的引用。在系统地释放对象一文中阅读更多相关内容。
| 归档时间: |
|
| 查看次数: |
462 次 |
| 最近记录: |