Tuesday, July 17, 2007

Retrieve Microsoft Exchange FreeBusy data

I wanted to show an exchange users calendar for the current day. There is a command you can use with Microsoft Outlook web access. At first I thought I could just call this command, parse the XML and display a table from 8am to 5pm showing out of office, in a meeting, etc..
What I didn’t realize is that you will always get back null unless you run the command on the exchange server. Microsft actually explains that you should use the command to make a web service.

You can also use CDOEX, (Collaboration Data Objects for Exchange), to retrieve the data. Again, this must be run on the exchange server. You’d have to find the cdoex.dll and regsvr32 it locally to add it to Visual Studio. You can find the dll on the exchange server or search the web. That code looks like this:

string freebusy = “EMPTY”;
int Interval = 30;
DateTime dtStartDate = DateTime.Parse(“2/8/2007 1:00:00 AM”);
DateTime dtEndDate = DateTime.Parse(“2/8/2007 11:00:00 PM”);


CDO.Addressee iAddr = new CDO.Addressee();
ActiveDs.ADSystemInfo Info = new ActiveDs.ADSystemInfo();

iAddr.EmailAddress = “example@example.com”;
if (!(iAddr.CheckName(“LDAP://” + Info.DomainDNSName, “”, “”)))
throw new System.Exception(“Error occured!”);

freebusy = iAddr.GetFreeBusy(dtStartDate, dtEndDate, 30, “”, “”, “”, “”);