Active Directory - InfoPath Dev
in

InfoPath Dev

Active Directory

Last post 12-12-2006 07:07 AM by braegger. 32 replies.
Page 3 of 3 (33 items) < Previous 1 2 3
Sort Posts: Previous Next
  • 12-12-2006 01:19 AM In reply to

    Hi Deb

    I faced the same problem and this worked at my side:

    public string GetCurrentUser(){
    return System.Environment.UserName;
    }
    public static DirectoryEntry GetDirectoryEntry(){
    string defaultNamingContext;
    using(DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE")){
    defaultNamingContext = "LDAP://" + root.Properties["defaultNamingContext"].Value;
    }
    DirectoryEntry entry = new DirectoryEntry(defaultNamingContext);
    return entry;
    }
    public static DirectorySearcher GetDirectorySearcher(DirectoryEntry entry){
    System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(entry);
    return search;
    }
    // propertyName: SamAccountName, mail, streetAdress, cn
    public string GetUserADProperties(string propertyName){
    DirectoryEntry entry = GetDirectoryEntry();
    DirectorySearcher search = GetDirectorySearcher(entry);
    search.Filter = "(&(&(objectClass=user)(SamAccountName=" + GetCurrentUser() + ")))";
    search.PropertiesToLoad.Add(propertyName);
    SearchResult result = search.FindOne();
    string propertyValue = "";
    if(result != null){
    propertyValue = result.Properties[propertyName][0].ToString();
    }
    return propertyValue;
    }

    hope it helps....
  • 12-12-2006 06:55 AM In reply to

    Holy cow, braegger. Thank you! I'm not a programmer so can only guess that this routine would be associated with the OnLoad event? If so, what variable does the username end up in and how do I use it?

    Geez, I so need to know how all this works. I've hit the ceiling with my knowledge of InfoPath and need to go to the next level and understand how to really get control over the tool!
  • 12-12-2006 07:07 AM In reply to

    Hi Deb

    I call this methods in the onLoad, but you can also call them in a change event.

    Say you have a field in your template named myField. And you want to safe data fron AD into this field.

    public XPathNavigator GetNode(string name){
    return CreateNavigator().SelectSingleNode("/my:myFields/my:" + name,this.NamespaceManager);
    }

    public void FormEvents_Loading(object sender,LoadingEventArgs e){
    GetNode("myField").SetValue(GetUserADProperties("cn"));
    }

    hope it helps...
Page 3 of 3 (33 items) < Previous 1 2 3
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.