public static string GetSingleStringPropertyCollectionValue(ResultPropertyCollection props, string name) { try { if (!props.Contains(name)) { return string.Empty; } ResultPropertyValueCollection pvc = props[name]; if (pvc == null || pvc.Count == 0) { return string.Empty; } if (string.Compare(name, Constants.Properties.AdProperties.ObjectSID) == 0) { byte[] sidInBytes = (byte[])pvc[0]; SecurityIdentifier sid = new SecurityIdentifier(sidInBytes, 0); return Convert.ToString(sid); } else { return Convert.ToString(pvc[0]); } } catch (Exception ex) { throw new ApplicationException(string.Format("Failed to retrieve property '{0}' from ResultPropertyCollection.", name), ex); } }
public static T SingleValue <T>(this ResultPropertyCollection col, string Property) { if (!col.Contains(Property)) { return(default(T)); } ResultPropertyValueCollection valueCol = col[Property]; if (valueCol.Count == 0) { return(default(T)); } return((T)valueCol[0]); }
private static string GetSingleStringPropertyCollectionValue(System.DirectoryServices.ResultPropertyCollection props, string name) { if (!props.Contains(name)) { return(string.Empty); } ResultPropertyValueCollection pvc = props[name]; if (pvc == null || pvc.Count == 0) { return(string.Empty); } return(pvc[0] as string); }
private static string GetObjectSid(System.DirectoryServices.ResultPropertyCollection props, string name) { if (!props.Contains(name)) { return(string.Empty); } ResultPropertyValueCollection pvc = props[name]; if (pvc == null || pvc.Count == 0) { return(string.Empty); } byte[] sidInBytes = (byte[])pvc[0]; SecurityIdentifier sid = new SecurityIdentifier(sidInBytes, 0); return(sid.ToString()); }
/// <summary> /// This method retrieves the set of users from active directory that meet the criteria specified in filter. /// </summary> /// <param name="sFilter"></param> /// <returns></returns> /// <remarks></remarks> public static List <string> FetchContacts(string sFilter = "") { // Exceptions are handled by the caller using (DirectorySearcher oSearcher = Initialize()) { if (oSearcher != null) { List <string> cNames = new List <string>(); // Specify what we are looking for, which is the account name of the specified user without any domain information oSearcher.Filter = string.Format("(&(objectCategory=person)(objectClass=user){0})", sFilter); // get all of the matching records using (SearchResultCollection cResults = oSearcher.FindAll()) { if (cResults != null) { foreach (SearchResult theCurrentResult in cResults) { System.DirectoryServices.ResultPropertyCollection oProperties = null; oProperties = theCurrentResult.Properties; // First, verify that at least the display name is contained in the result if (oProperties.Contains(PROPERTY_DISPLAY_NAME) && oProperties[PROPERTY_DISPLAY_NAME].Count > 0) { cNames.Add(oProperties[PROPERTY_DISPLAY_NAME][0].ToString()); } } } } return(cNames); } } return(null); }
public static string GetSingleStringPropertyCollectionValue(ResultPropertyCollection props, string name) { if (!props.Contains(name)) { return string.Empty; } ResultPropertyValueCollection pvc = props[name]; if (pvc == null || pvc.Count == 0) { return string.Empty; } if (string.Compare(name, Constants.Properties.AdProperties.ObjectSID) == 0) { byte[] sidInBytes = (byte[])pvc[0]; SecurityIdentifier sid = new SecurityIdentifier(sidInBytes, 0); return Convert.ToString(sid); } else { return pvc[0] as string; } }