Need tremendous help gettin UserName from an AD - InfoPath Dev
in

InfoPath Dev

Need tremendous help gettin UserName from an AD

Last post 11-29-2006 04:44 PM by Patrick Halstead. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 11-22-2006 01:03 AM

    • Linus
    • Not Ranked
    • Joined on 11-22-2006
    • Posts 4

    Need tremendous help gettin UserName from an AD

    Hey guys!!!

    I'm stucking in dirt like no one before. My Boss told me to create a InfoPath Formular that should include a text fild that shall be filled with the current user's name on load. His words 'This can be done with some c# code' - Blue eyed I said 'Absolutely no prob!' and startet to write some code. As awaited, the c# worked. Then I tried to implement the c# code into the formular, realizing it ain't gonna work that way.

    My first question is: Is it possible to implement c# code into a formular?

    I've no idea about jscript. But I think I'm not the first trying to get the username (Lastname + Forename) so the second question is:

    Do you have a working js code solving my problem? - I didn't find some code or just didn't understand...

    If I can't do this, I'll be dead on monday... 'cause my boss'll be back from vacation that day!!!

    Seriously -> Help!!! ... much!!!

    Greetings from Germany, Sycho Sid
  • 11-22-2006 02:47 AM In reply to

    Re: Need tremendous help gettin UserName from an AD

    Hi,

    Try out these link
    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=683
    Hope this will help you
  • 11-22-2006 03:06 AM In reply to

    • Linus
    • Not Ranked
    • Joined on 11-22-2006
    • Posts 4

    Re: Need tremendous help gettin UserName from an AD

    Yeah, sounds good. I'll give it a try...

    later
  • 11-22-2006 06:30 AM In reply to

    • Linus
    • Not Ranked
    • Joined on 11-22-2006
    • Posts 4

    Re: Need tremendous help gettin UserName from an AD

    Problem!

    I don't know the URL for the ADServices... What could I do to get it?

    greets
  • 11-22-2006 11:18 AM In reply to

    Re: Need tremendous help gettin UserName from an AD

    Hi Linus and welcome!
    You need to install it first. :) It's $19.95. If you buy it and it doesn't solve your problem, let me know and we'll refund you.
    Patrick Halstead
    Project Manager at Qdabra
  • 11-22-2006 11:23 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Need tremendous help gettin UserName from an AD

    Hi Linus,

    Check out these links,
    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=612

    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1677
  • 11-22-2006 11:19 PM In reply to

    • Linus
    • Not Ranked
    • Joined on 11-22-2006
    • Posts 4

    Re: Need tremendous help gettin UserName from an AD

    Hi guys!

    We already have an AD in our network. Or do I havo to install that service on my local computer?

    Linus
  • 11-23-2006 12:50 PM In reply to

    Re: Need tremendous help gettin UserName from an AD

    Hi Linus,
    If you have AD, then you just need to install the service on one of your web servers where IIS and ASP.NET are already installed. Good luck!
    Patrick Halstead
    Project Manager at Qdabra
  • 11-28-2006 11:18 PM In reply to

    Re: Need tremendous help gettin UserName from an AD

    Hey Linus,

    first install the InfoPath toolkit for Visual Studio that you can use managed code for you InfoPath projects. Then put this into the OnLoad event of your form to get the currently logged on users name form AD.

    NOTE: This requires to set your form to full trust level.
    If you don't want to do so use the code with a WebService.

    IXMLDOMNode name	  = thisXDocument.DOM.selectSingleNode("my:myFields/my:name");
    try
    {
    string user = System.Environment.UserName;

    // Create a directory searcher on the path provided when created the instance
    DirectoryEntry entry = new DirectoryEntry("LDAP://OU= ,DC=,DC=,DC=");
    DirectorySearcher searcher = new DirectorySearcher(entry);

    string ToFind = "(SAMAccountName=" + user + ")";
    searcher.Filter = ToFind;

    // Try to find the employee
    SearchResult result = searcher.FindOne();
    if (result != null)
    {
    // Get the 'DirectoryEntry' that corresponds to 'result'.
    DirectoryEntry myDirectoryEntry = result.GetDirectoryEntry();

    // Get the properties of the 'mySearchResult'.
    ResultPropertyCollection myResultPropColl;
    myResultPropColl = result.Properties;

    foreach(Object myCollection in myResultPropColl["name"])
    {
    PE.text = myCollection.ToString();
    }
    name.text = "Name Set";
    }
    }
    catch (Exception ex)
    {
    ex.Message.ToString();
    }
    Listen to Motörhead cos they play Rock'n Roll :)
  • 11-29-2006 12:22 AM In reply to

    Re: Need tremendous help gettin UserName from an AD

    Thanks again Nukkumatti for the excellent post! Aside from Full Trust and potential security or hardcoding issues encoding the the LDAP string in code, I generally tell people to minimize the code in their solution since that will make them less costly to maintain longterm.
    Patrick Halstead
    Project Manager at Qdabra
  • 11-29-2006 02:24 AM In reply to

    Re: Need tremendous help gettin UserName from an AD

    You are absolutely right Patrick.
    If you use the code with a WebService you could at least store the LDAP string in the config file and read it from there to be at least somehow a bit dynamic.
    By the way finally got "your" book "Developing Solutions with InfoPath". Nice piece of paper. I guess it would have helped me a lot when I started working with InfoPath but I guess it still will.
    Listen to Motörhead cos they play Rock'n Roll :)
  • 11-29-2006 04:44 PM In reply to

    Re: Need tremendous help gettin UserName from an AD

    We are about ready to start a free isntall campaign where we will be giving our AD web service away for free as part of the more significant Qdabra Database Accelerator Suite. The suite will include numerous articles on how to create InfoPath solutions and integrate with SQL Database and Active Directory without writing any code.

    Watch here for a release announcement in the next 3-4 weeks.
    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.