OWA: How to Get Freebusy Information

The following HTTP Request uses an OWA command to retrieve Freebusy information for a particular user…

//************************************

// Print out FreeBusy XML string to console

// Created By: mstehle

// Created On: 6/8/06

//************************************

public string GetFreeBusy(string userSMTP, DateTime start,

    DateTime end, int interval)

{

    string freebusyURL = string.Format(

        "https://{0}/public/?cmd=freebusy&start={1}&end={2}&interval={3}&u=SMTP:{4}",

        _server, Utils.ConvertToISO8601(start, true),

        Utils.ConvertToISO8601(end, true),

        interval.ToString(), userSMTP);

   

    // DEBUG: Print out the FreeBusy URL

    Debug.WriteLine("Request URL: " + freebusyURL);

    // Create the HttpWebRequest object.

    System.Net.HttpWebRequest request =

        (System.Net.HttpWebRequest)HttpWebRequest.Create(freebusyURL);

    // Create credentials from user name and password

    System.Net.CredentialCache creds = new CredentialCache();

    System.Uri folderUri = new Uri(freebusyURL);

    System.Net.NetworkCredential netCred =

        new NetworkCredential(_userName, _password, _domain);

    creds.Add(folderUri, "Basic", netCred);

    request.Credentials = creds.GetCredential(folderUri, "Basic");

    // Specify the method.

    request.ContentType = "text/xml";

    request.Method = "GET";

    request.KeepAlive = true;

    request.AllowAutoRedirect = false;

    // NOTE: Response will return with HTML not XML if UserAgent isn't set!

    request.UserAgent = "Mozilla/4.0(compatible;MSIE 6.0; " +

        "Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)";

    // Send the SEARCH method request and get the

    // response from the server.

    System.Net.HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    System.IO.Stream responseStream = response.GetResponseStream();

    System.IO.StreamReader responseReader = new System.IO.StreamReader(responseStream);

    string strResponse = responseReader.ReadToEnd();

    // Clean up.

    responseReader.Close();

    responseStream.Close();

    response.Close();

    // DEBUG: Print out the response string

    Debug.WriteLine(strResponse);

    return strResponse;

}

Calling this function passing the full SMTP address of the user whose calendar you are querying, the start and end times of your query, and an interval (in minutes) to return results returns XML as seen below. This was a query I did against a resource mailbox to check the availability of the Death Star with an block of time. As you can see the Death Star’s schedule is wide open.

<a:response xmlns:a="WM">

<a:recipients>

<a:item>

<a:displayname>All Attendees</a:displayname>

<a:type>1</a:type>

<a:fbdata>000000000000000000000000000000000000000000000000</a:fbdata>

</a:item>

<a:item>

<a:displayname>Death Star</a:displayname>

<a:email type="SMTP">deathstar@mstehle03.extest.microsoft.com</a:email>

<a:type>1</a:type>

<a:fbdata>000000000000000000000000000000000000000000000000</a:fbdata></a:item>

</a:recipients>

</a:response>

…For more information see the following MSDN articles…

Checking Free/Busy Status (HTTP)

https://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_esdk_checking_free_busy_status_http.asp

Checking Free/Busy Status

https://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_checking_free_busy_status.asp

…Also note that this is one of the few OWA commands that are supported for use in an application. Many customers attempt to integrate OWA commands into their applications. It is worth noting that most are *not* supported in this fashion. The Freebusy URL is one of the few exceptions…

P.S.

Here is the code for the ConvertToISO8601 function that you see I use above. This simply takes a .NET DateTime and converts it to a DAV-friendly ISO 8601 formatted date…

// ************************************

// Created By: mstehle

// Created On: 6/8/06

// Converts the given System.DateTime to an ISO 8601 DATE-TIME formatted string

// for use with DAV.

// ************************************

public static string ConvertToISO8601(DateTime myDT, bool noMili)

{

    if (!noMili)

    {

        return myDT.ToString("yyy-MM-ddT") + myDT.Hour + myDT.ToString(":mm:ss.000Z");

    }

    else

    {

        return myDT.ToString("yyy-MM-ddT") + myDT.Hour + myDT.ToString(":mm:ssZ");

    }

}

public static string ConvertToISO8601(DateTime myDT)

{

    return ConvertToISO8601(myDT, false);

}