IndexOutOfRangeException: Index was outside the bounds of the array
string propertyName = "mail"; string User = HttpContext.Current.User.Identity.Name; // System.Environment.UserName; string[] Name = Regex.Split(User.Trim(), @"\\"); string username = Name[1]; //string domainname = HttpReq//System.Environment.UserDomainName.ToString().ToLower(); string domainname = Name[0]; //"AsiaPacific"; DirectoryEntry entry = new DirectoryEntry("LDAP://DC=" + domainname + ",DC=cpqcorp,DC=net"); DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(&(&(objectClass=user)(SamAccountName=" + username + ")))"; search.PropertiesToLoad.Add(propertyName); SearchResult result = search.FindOne(); string propertyValue = ""; if (result != null) { propertyValue = result.Properties[propertyName][0].ToString(); //propertyValue = result.Properties.Count.ToString(); } return propertyValue;
Exception Error: [IndexOutOfRangeException: Index was outside the bounds of the array.] clsCommon.DisplayName()
Name[0]
Name[1]
result.Properties[propertyName][0]
result.Properties[propertyName]
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)