InfiniTec - Henning Krauses Blog

Don't adjust your mind - it's reality that is malfunctioning

A WebDAV PROPPATCH which works for Exchange 2003 breaks with Exchange 2007

If you are using WebDAV to store data in Exchange you may encounter a breaking change when migrating from Exchange 2003 to 2007: A PROPPATCH request which works flawlessly with Exchange 2003 will break with Exchange 2007 returning a 400 Bad Request error.

This may happen if you upload data to the Exchange server containing control characters (chars 0x00 through 0x1f). If this happens inside a HTML-based property (e.g. the HTML body of the email), you can use the following workaround to encode the characters in question. Otherwise you should probably just strip them away.

Workaround

If you are using a .NET based language you can utilize a simply regular expression to convert or strip the invalid values from the data:

    1 Regex _ControlReplacer = newRegex("\\p{Cc}", RegexOptions.Compiled);

    2 

    3 // Use this line if you want to encode the control characters using HTML entities

    4 string result = _ControlReplacer.Replace(data, delegate(Match match) { return"&#x" + Convert.ToInt32(match.Value[0]).ToString("x2") + ";"; });

    5 

    6 // Use this line if you want to strip the control characters from the data

    7 string result = _ControlReplacer.Replace(data, "");


Technorati:

Posted by Henning Krause on Tuesday, September 18, 2007 12:00 AM, last modified on Tuesday, September 18, 2007 12:00 PM
Permalink | Post RSSRSS comment feed