【发布时间】:2015-07-14 14:43:07
【问题描述】:
我正在尝试编写一些 c# 代码来与 Outlook 2010 交互。我目前使用的是this example from Microsoft。
我的代码如下:
using System;
using System.Text; // StringBuilder
using System.Diagnostics; // Debug
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace DirectReports
{
public class Program
{
private void GetManagerDirectReports()
{
Outlook.AddressEntry currentUser = Application.Session.CurrentUser.AddressEntry;
//Outlook.AddressEntry currentUser = Outlook.Application.Session.CurrentUser.AddressEntry;
if (currentUser.Type == "EX")
{
Outlook.ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();
if (manager != null)
{
Outlook.AddressEntries addrEntries =
manager.GetDirectReports();
if (addrEntries != null)
{
foreach (Outlook.AddressEntry addrEntry
in addrEntries)
{
Outlook.ExchangeUser exchUser = addrEntry.GetExchangeUser();
StringBuilder sb = new StringBuilder();
sb.AppendLine("Name: " + exchUser.Name);
sb.AppendLine("Title: " + exchUser.JobTitle);
sb.AppendLine("Department: " + exchUser.Department);
sb.AppendLine("Location: " + exchUser.OfficeLocation);
Debug.WriteLine(sb.ToString());
}
}
}
}
}
}
}
Microsoft 示例中提到“如果您使用 Visual Studio 测试此代码示例,则必须首先添加对 Microsoft Outlook 15.0 对象库组件的引用”。我正在为 Windows 桌面使用 Visual Studio Express 2013。我没有看到 15.0 版本的对象库,而是添加了 14.0 版本的对象库(无论如何我认为它适合 Outlook 2010):
当我尝试构建时,我收到以下错误:
The name 'Application' does not exist in the current context
我阅读了一些参考资料,表明Application 应该是上述对象库的一部分,但显然它在这里不起作用。有人可以建议我做错了什么吗?
【问题讨论】: