Last active
August 29, 2015 14:04
-
-
Save slmcmahon/a263ffe2d51324d4f275 to your computer and use it in GitHub Desktop.
Check System.DirectoryServices.SearchResult for byte[] or string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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