Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1.         public static IList<string> SetUserInformation()
  2.         {  
  3.             string locCode = string.Empty;
  4.             string firstName = string.Empty;
  5.             string lastName = string.Empty;
  6.             string contactInfo = string.Empty;
  7.             string mail = string.Empty;
  8.             string phone = string.Empty;
  9.             string ext = string.Empty;
  10.  
  11.             IList<string> data = new List<string>();
  12.             string userName, userPassword;
  13.  
  14.             userName = "Hpd016AspNet";
  15.             userPassword = "asp.net";
  16.  
  17.             DirectoryEntry entry = new DirectoryEntry("LDAP://us.parker.corp/OU=FCG,DC=us,DC=parker,DC=corp", userName, userPassword);
  18.  
  19.  
  20.                 DirectorySearcher searcher = new DirectorySearcher(entry);
  21.                 searcher.SearchRoot = entry;
  22.  
  23.                 string currentUser = HttpContext.Current.User.Identity.Name;
  24.                 currentUser = currentUser.Remove(0, 6);
  25.                 searcher.Filter = "(&(objectClass=user)(userPrincipalName=*" + currentUser + "*))";
  26.                 searcher.SearchScope = SearchScope.Subtree;
  27.                 searcher.PropertiesToLoad.Add("displayName");
  28.                 searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
  29.                 searcher.PropertiesToLoad.Add("givenname");
  30.                 searcher.PropertiesToLoad.Add("sn");
  31.                 searcher.PropertiesToLoad.Add("mail");
  32.                 searcher.PropertiesToLoad.Add("telephonenumber");
  33.                 searcher.PropertiesToLoad.Add("extension");
  34.  
  35.                 SearchResult result = searcher.FindOne();
  36.  
  37.                 if (result != null)
  38.                 {
  39.                     ResultPropertyCollection props = result.Properties;
  40.  
  41.                     foreach (DictionaryEntry x in props)
  42.                     {
  43.  
  44.                         switch (x.Key.ToString().ToLower())
  45.                         {
  46.                             case "physicaldeliveryofficename":
  47.                                 locCode = props["physicalDeliveryOfficeName"][0].ToString();
  48.                                 break;
  49.                             case "givenname":
  50.                                 firstName = props["givenname"][0].ToString();
  51.                                 break;
  52.                             case "sn":
  53.                                 lastName = props["sn"][0].ToString();
  54.                                 break;
  55.                             case "mail":
  56.                                 mail = props["mail"][0].ToString();
  57.                                 break;
  58.                             case "telephonenumber":
  59.                                 phone = props["telephonenumber"][0].ToString();
  60.                                 break;
  61.                             case "extension":
  62.                                 ext = props["extension"][0].ToString();
  63.                                 break;
  64.                             case "displayname":
  65.                                 break;
  66.                             default:
  67.                                 break;
  68.                         }
  69.  
  70.                     }
  71.                 }
  72.            
  73.  
  74.             data.Add(locCode);
  75.             data.Add(firstName);
  76.             data.Add(lastName);
  77.             contactInfo = mail + " " + phone + " " + ext;
  78.  
  79.             data.Add(mail);
  80.             data.Add(phone + " " + ext);
  81.             data.Add(contactInfo);
  82.  
  83.             return data;
  84.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement