Well, though I beleive very few of us have to actually track the iCalendar specification and code against it, it becomes neccessary especially when your mail server is not Exchange and you do not find a free adapter. Besides, even to use the free busy information from the Exchange data store in a custom application, we need to know what is to be done. I will share the ways to do it, both in an Exchange and a non-Exchange environment:
Accessing Free Busy Information – Exchange
1. Using Object Model to get the bits
This is fairly easy:
Recipient oRecip;
AddressEntry oAddrEntry;
oRecip = oApp.Session.CreateRecipient(<Exchange alias>);
if (oRecip.Resolve()==true)
{
oAddrEntry = oRecip.AddressEntry;
mylistBox.Items.Add(oAddrEntry.GetFreeBusy(DateTime.Now, 15, true));
}
2. Using WebDAV
Use the second function in specific cases:
public void PrintInfoUsingExchangeWebDAV(string id,string password,string domain,string serverid,string usersmtp)
string server = <Your Exchange Server>;
NetworkCredential credentials = new NetworkCredential(id, password, domain);
string uri = string.Format("https://{0}/public/?cmd=freebusy&start=2007-09-06T09:00:00+05:30&end=2007-09-06T14:00:00+05:30&interval=60&u=SMTP:{1}", serverid, usersmtp);
HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
request.Credentials = credentials;
request.Method = "GET";
request.ContentType = "text/xml";
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(GetAuthCookies(server, credentials));
request.KeepAlive = true;
request.AllowAutoRedirect = false;
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)";
try
System.Net.HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
txt_Response.Text = responseFromServer;
response.Close();
reader.Close();
dataStream.Close();
catch (Exception ex)
string msg = ex.Message;
throw (ex);
// When Exchange is setup for Forms Authentication you need to do the login separately
public CookieCollection GetAuthCookies(string server, NetworkCredential credentials)
// URI to OWA authorization dll
string authURI = string.Format("{0}/exchweb/bin/auth/owaauth.dll", server, credentials.UserName);
byte[] bytes = Encoding.UTF8.GetBytes(string.Format("destination={0}/exchange/{1}&username={2}\\{1}&password={3}", server, credentials.UserName, credentials.Domain, credentials.Password));
HttpWebRequest request = WebRequest.Create(authURI) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencode";
request.ContentLength = bytes.Length;
using (Stream requestStream = request.GetRequestStream())
requestStream.Write(bytes, 0, bytes.Length);
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
return response.Cookies;
3. Using Exchange Web Services
I am not documenting this section in details as it is specific to Exchange 2007 and beyond. But certainly is the recommended approach for the future. Peep into:
http://msdn2.microsoft.com/en-us/library/bb408417.aspx
Accessing Free Busy Information – Non Exchange
This can be tricky. Create your own .vfb file parser to return you the status bits. Bind the appropriate values to the presentation UI. I had once written such a parser to read from Oracle Collaboration suite and will try to make the assembly available for re-use. However, I certainly do not recommend this as an approach as the product team has spent a sizeable amount of time in devising a very sound parser. One should ideally trick around and use the Outlook’s page control to play in such a situation. I will post the tricks to do that. Then just add recipients to the page control and allow Outlook to look up the free busy information from the configured location.