Skip to content

Instantly share code, notes, and snippets.

@slmcmahon
Last active August 29, 2015 14:04
Show Gist options
  • Save slmcmahon/a263ffe2d51324d4f275 to your computer and use it in GitHub Desktop.
Save slmcmahon/a263ffe2d51324d4f275 to your computer and use it in GitHub Desktop.
Check System.DirectoryServices.SearchResult for byte[] or string
private string GetDataFromResults(SearchResult result, string propertyName)
{
if (!result.Properties.Contains(propertyName) || result.Properties[propertyName].Count == 0)
{
return null;
}
var prop = result.Properties[propertyName][0];
var data = prop.GetType() == typeof (byte[])
? Encoding.UTF8.GetString((byte[]) prop)
: prop.ToString();
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment