Using C# to get the free/busy status of user

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I am using the following C# code to get the freeBusy status of a user. However, the
getFreeBusy function is returning null. The code is part of a service I have
running on my local machine which is in the same domain as Exchange server (2003).
Does anyone have any suggestions? Thank you.


public void readFreeBusyString(DateTime dtStartDate,
DateTime dtEndDate, int Interval)
{
try
{
// Variables.
CDO.Addressee iAddr = new CDO.Addressee();
ActiveDs.ADSystemInfo Info = new ActiveDs.ADSystemInfo();

iAddr.EmailAddress = this.email;
if (!(iAddr.CheckName("LDAP://" + Info.DomainDNSName, "", "")))
throw new System.Exception("Error occured!");

// Get the free/busy status in Interval minute
// intervals from dtStartDate to dtEndDate.
this.freebusy = iAddr.GetFreeBusy(dtStartDate, dtEndDate, Interval, "", "", "", "");

}
catch (Exception err)
{
//write to the event log
}
}
 
Hi Jeff,

I found a solution, but you have to use CDO 1.2.1
Try this link: http://support.microsoft.com/default.aspx?scid=kb;en-us;186753

Here is my Vb.Net implementation:

Private Function strGetFreeBusy() As String

Dim ObjSession As MAPI.Session
Dim ObjMessage As Message
Dim ObjAddressEntry As AddressEntry

Dim freebusyTray As String
Dim ObjRecipColl As Object
Dim objOneRecip As Object

Try
ObjSession = CreateObject("mapi.session")
'Default local logon
ObjSession.Logon(profilename:="Default Outlook Profile")
ObjMessage = ObjSession.Inbox.Messages.Add
ObjRecipColl = ObjMessage.Recipients
objonerecip = ObjRecipColl.Add

'Type the alias of the person or the resource account.
objonerecip.Name = "Test, User"
objonerecip.Resolve()
MsgBox(objonerecip.Address)
ObjAddressEntry = objonerecip.AddressEntry

'Specify the date/time of the beginning of the first time slot.
Dim starttime As Date
starttime = "2004/08/17 8:00:00 AM"

'Specify the date/time of the end of the last time slot.
Dim endtime As Date
endtime = "2004/08/18 10:00:00 AM"

'Specify the length of each time slot in minutes.
'If Interval parameter is less than 1, GetFreeBusy returns
'CdoE_INVALID_PARAMETER.

Dim interval As Integer
interval = 60
'Interval parameter determines the number of time slots.
'For this example, Interval is set to 60 minutes. Therefore,
'there will be 2 time slots between the StartTime and the EndTime.
'The first time slot is between 8:00:00-9:00:00 AM.
'The second time slot is between 9:00:00-10:00:00 AM.

freebusyTray = ObjAddressEntry.GetFreeBusy(starttime, endtime, _
interval)
'Since there are two time slots, the GetFreeBusy method returns a
'string with length 2. For example, FreeBusy = "21" indicates that
'there is a tentative commitment during the time slot 1. Also,
'there is a confirmed commitment during the time slot 2.

Catch ex As Exception
Return ex.Message
Finally
ObjSession.Logoff()
ObjMessage = Nothing
ObjRecipColl = Nothing
objonerecip = Nothing
ObjAddressEntry = Nothing
ObjSession = Nothing
End Try

Return freebusyTray

End Function

Have fun

Chris
 
Back
Top