我正在尝试在 Windows XP SP3 和 Internet Explorer 7 上使用 Visual Studio 2008 创建 Outlook 2003 加载项。
我的加载项使用自定义文件夹主页,它显示我的自定义表单,它包装了 Outlook View Control。
每次尝试设置 OVC 的文件夹属性时,我都会收到带有“HRESULT 异常:0xXXXXXXXX”描述的 COM 异常。错误码是一个随机数,每次都不一样。这不是第一次访问控件的属性,在此之前,已经设置了 View 和 ViewXML 属性。控件被标记为可安全编写脚本。
我正在使用事件资源管理器的 CurrentFolder.FolderPath 属性的值,这似乎是正确的:
Outlook.Explorer currentExplorer = app.ActiveExplorer();
if (currentExplorer != null)
{
ovcWrapper.Folder = currentExplorer.CurrentFolder.FolderPath;
}
这是堆栈跟踪的顶部:
System.Runtime.InteropServices.COMException (0xXXXXXXXX): Exception from HRESULT: 0xXXXXXXXX
at Microsoft.Office.Interop.OutlookViewCtl.ViewCtlClass.set_Folder(String pVal)
at AxMicrosoft.Office.Interop.OutlookViewCtl.AxViewCtl.set_Folder(String value)..
仅当文件夹位于非默认 PST 文件中时才会发生这种情况。更改为默认 PST 文件中的文件夹不会产生异常。
我必须强调,在我去度假之前一切都很好 :)。似乎 Windows XP 安装了一些更新,在我不在时更改了 Internet Explorer 或 Outlook 2003 的默认安全性。
在装有 Office 2007 和 Internet Explorer 6 的另一台(虚拟机)上,没有任何更新,一切正常。
最佳答案
一段时间后,我终于找到了解决方案:将外部存储的名称更改为新名称。
在插件启动期间,它会加载非默认 PST 文件,并将其名称(不是 pst 文件的名称,而是根文件夹的名称)更改为“Documents”。
这是代码:
session.AddStore("C:\\test.pst"); // loads existing or creates a new one, if there is none.
storage = session.Folders.GetLast(); // grabs root folder of the new fileStorage.
if (storage.Name != storageName) // if fileStorage is brand new, it has default name.
{
storage.Name = "Documents";
session.RemoveStore(storage); // to apply new fileStorage name, it have to be removed and added again.
session.AddStore(storagePath);
}
解决方案是不再使用“Documents”作为名称,而是使用新名称。问题与具体名称无关。
关于c# - 嵌入式 Outlook View 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/133194/