I am trying to write some c# code to interact with Outlook 2010. I am currently using this example from Microsoft.
My code follows:
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());
}
}
}
}
}
}
}
The Microsoft example mentions "If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component". I am working in Visual Studio Express 2013 for Windows Desktop. I did not see a version 15.0 object library, but added the version 14.0 one instead (which I think it the right one for Outlook 2010 anyways):
When I attempt a build, I get the following error:
The name 'Application' does not exist in the current context
I read a couple of references that indicate Application
should be part of the above object libraries, but obviously it is not working here. Can someone please suggest what I am doing wrong?