C# 如何使用WPF business app从outlook获取有关当前用户通讯组列表的信息
在我的WPF应用程序中,我需要基于团队启用/禁用功能。团队信息配置为outlook通讯组列表。现在我需要从我的应用程序中检索此信息 我在谷歌上搜索并找到了链接 不幸的是,它没有按原样编译。经过一点研究,我可以通过将其更改为C# 如何使用WPF business app从outlook获取有关当前用户通讯组列表的信息,c#,wpf,outlook,C#,Wpf,Outlook,在我的WPF应用程序中,我需要基于团队启用/禁用功能。团队信息配置为outlook通讯组列表。现在我需要从我的应用程序中检索此信息 我在谷歌上搜索并找到了链接 不幸的是,它没有按原样编译。经过一点研究,我可以通过将其更改为 currentUser = new Outlook.Application().Session.CurrentUser.AddressEntry; 但是,这仅在打开outlook时有效,但在关闭outlook时会引发异常。有什么想法吗?你能说得更
currentUser = new Outlook.Application().Session.CurrentUser.AddressEntry;
但是,这仅在打开outlook时有效,但在关闭outlook时会引发异常。有什么想法吗?你能说得更具体一点吗?代码中有什么异常(错误消息和错误代码) 我建议从断开调用链开始,在单独的一行中声明每个属性或方法调用。因此,您将发现引发异常的有问题的属性或方法调用
很可能需要调用命名空间类的Logon方法。例如,您可能会发现示例项目很有帮助 我终于设法破解了它。显然,我们需要简单地启动outlook应用程序,解决方案将在链接中解释 因此,我稍微修改了代码GetCurrentUserMembership(),以适应此更改。现在它工作得很好。在outlook 2007和2010中测试 完整的解决方案
private List<string> GetCurrentUserMembership()
{
Outlook.Application outlook = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector oInspector = oMsg.GetInspector;
//session.Logon("", "", false, false);
var sb = new List<string>();
Outlook.AddressEntry currentUser = outlook.Session.CurrentUser.AddressEntry;
if (currentUser.Type != "EX") return sb;
var exchUser = currentUser.GetExchangeUser();
if (exchUser == null) return sb;
var addrEntries = exchUser.GetMemberOfList();
if (addrEntries == null) return sb;
foreach (Outlook.AddressEntry addrEntry in addrEntries)
{
sb.Add(addrEntry.Name);
}
return sb;
}
私有列表GetCurrentUserMembership()
{
Outlook.Application Outlook=新建Outlook.Application();
Outlook.MailItem oMsg=(Outlook.MailItem)Outlook.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector oInspector=oMsg.GetInspector;
//session.Logon(“,”,false,false);
var sb=新列表();
Outlook.AddressEntry currentUser=Outlook.Session.currentUser.AddressEntry;
如果(currentUser.Type!=“EX”)返回sb;
var exchUser=currentUser.GetExchangeUser();
如果(exchUser==null)返回sb;
var addrEntries=exchUser.GetMemberOfList();
如果(addrEntries==null)返回sb;
foreach(addrEntries中的Outlook.AddressEntry addrEntry)
{
某人加上(地址名称);
}
归还某人;
}
我收到异常System.Runtime.InteropServices.ComeException。正如我在邮件中提到的,它在outlook打开时工作,但在outlook关闭时引发此异常。哪个属性或方法确切触发异常?您是否设置了没有密码的默认配置文件?您是否有机会查看正在运行的进程列表?有Outlook.exe吗?谢谢你的时间,我自己设法破解了,请看下面的帖子。但是你在登录方法上有一个例外,我错了吗?