InfoPath: How To Populate a List Control With SharePoint Users

Since the Service Pack 1 Preview of InfoPath it is really simple to fill for example a drop-down list box on a InfoPath form with data that is stored in a SharePoint list. But it’s not quite straight forward to fill that drop-down list box with all the users of a SharePoint site. Although this is quite easy to accomplish in a custom SharePoint list by creating a Lookup column and indicating that you want to get User Information. But (almost) nothing is impossible with InfoPath, so let’s give it a try!

First of all: how can we get a hold of a list with all the users of a specific SharePoint site? Well it happens to be that SharePoint exposes quite a lot of functionality through a web services layer; to be more specific: we can use the Users and Groups Service. In this service are several methods that you can use to retrieve all kinds of information about users and groups, we’ll use the GetUserCollectionFromSite method. So far so good, we know where to get our data, now let’s create the InfoPath form. The solution I’ll describe here will be using some custom code which can be written in script or in .NET code. This time, let’s make use of the InfoPath 2003 Toolkit for Visual Studio.NET so we can write .NET code.

Thus let’s fire up Visual Studio .NET and choose to create a new project based on the InfoPath Form Template. Drop a drop-down list box on your InfoPath form and open the Properties window. In the “List box entries” section choose to “Look up values in a data connection to a database, Web service, file or SharePoint library or list”. At this point the InfoPath form doesn’t have any data connections, hence click the Add button to create a new one. We want to get our data from the GetUserCollectionFromSite web method, so select the “Web service” option in the wizard. For the WSDL location use a URL formatted as follows: http://Server_Name/[Site_Name/]_vti_bin/UserGroup.asmx?wsdl (for example: http://myServer/SharePoint/_vti_bin/UserGroup.asmx?wsdl). Next the wizard will show you a list containing all the web methods available on the web service, select the GetUserCollectionFromSite method. Finally you can give the data connection a name, let’s call it “Users”. When you click the Select XPath button (right to the Entries text box), the troubles begin… As you can see on the screenshot, the web service return value does not contain a repeating group or field, which is necessary to be able to fill a list.

Why is that? Well if we take a look at the GetUserCollectionFromSite documentation we can see that the return value is of the System.Xml.XmlNode type. That means that you’ll receive XML of which the WSDL doesn’t describe how it will look like, so InfoPath can’t show your either. Although the documentation shows an example of how the XML will look like, it’s quite a bummer. The problem would be solved if you could type the XPath value in the Entries text box, but unfortunately this text box is read-only. From now on, there are several possible solutions:

  • Manually edit the XSLT of the InfoPath form and fill in the correct XPath value.
  • Create a wrapper web service that exposes the GetUserCollectionFromSite information strongly typed.
  • Use the little trick I’ll show you in a moment. :-)

The third solution will make use of a dummy data connection that has the same structure as the return value of the web method. This will give you the advantage of using InfoPath functionality to select the correct repeating group. Afterwards the contents of that dummy data connection are replaced by return value of the web method. So let’s work further on our InfoPath form but first download this XML file to your harddisk; it contains a fictitious return value of the GetUserCollectionFromSite web method. Click the Add (data connection) button to add a new one data connection: receive data from an XML document (point to the file you’ve just downloaded) and name it “DummyUsers”. Un-check the “Automatically retrieve data when the form is opened” check box and choose No if InfoPath suggest to file to your form. Then open the Properties window of the drop-down list box control again, select the “Look up values in a data connection to a database, Web service, file or SharePoint library or list” option, and choose to DummyUsers data connection. Then if you choose the “Select XPath” button you’ll see that you can navigate to a repeating group! Also in the Properties window, you need to specify the Value and “Display name” field, for example choose the LoginName field for both ones.

We’re not finished yet, we need to replace the data of the DummyUsers data connection with the data of the Users data connection (which is automatically fetched through the web service). We must do this in the OnLoad event of the InfoPath form, so in the Tools/Programming menu click the “On Load Event” menu item. Visual Studio.NET will pop up, and a the OnLoad method is created for you. You need only to add one line:

// The following function handler is created by Microsoft Office InfoPath. Do not
// modify the type or number of arguments.
public void OnLoad(DocReturnEvent e)
            // Write your code here.

That’s it! If you preview the InfoPath form, first the data of the Users data connection is fetched automatically. Then the OnLoad event is triggered, so we replace the data of the DummyUser data connection, and finally the form is showed and the drop-down list box contains all the login names of the users of the SharePoint site. You can use this little trick also for fetching other data through the SharePoint web services. If you want to easily create dummy XML documents you can use the WebServiceStudio 2.0 that can construct SOAP request messages.


  • It's great, Jan i've search this trick around the world :)

    Tanks, italy

  • very slick. thanks!

  • Is possible to change views during the OnLoad event?, thanks.

  • Daniel, can you elaborate a little bit more what you are trying to do?

  • dfsdafsdf





  • Thanks for the tip! I was trying to figure out how to do this with Sharepoint 2 and it doesnt appear that I need the extra steps but it showed me how to get the list to the usernames URL.

  • Hey, when I try this I get:


    An item with the following index does not exist in the collection: Users


    Any ideas?

  • Never mind, figured it out. I never renamed the first data source "Users"

  • HI

    its possible to open a popup window in infopath form and select value from that popup window to parent infopath form.



  • HI

    its possible to open a popup window in infopath form and select value from that popup window to parent window.



  • Thanks a lot. It made my day.

  • I was successful with this demo but I would like to use the GetUserInfo Method to retreive the current user opening the form and then present customized user specific information.
    When I preview the form with the data connection to this method autoloading however I get an error that the form tmeplate is invalid and an error message stating that the parameter loginName cannot be empty.
    Maybe I am using the wrong method or there are some other things that must be done.
    If anycome can give me come advice on how to get the current user of the form from sharepoint please let me know.
    cefox at

    Thank You.

  • It is really a very good example, Is it possible that we can fetch users from a perticular Sitegroup.

  • I'm desperate. I need to get current user name. Pls help

  • I need to be able to populate a dropdownlist programmatically.
    There are some articles out there that explains how, but i am unable to make it works. Please help?



  • After promoting the infopath user property to Sharepoint site , Is it possible to filter a view using [Me] in WSS 3.0 or MOSS 2007?

  • I just like to say that your website is absoulutely brilliant!!! Do you think my sites too brilliant ;) ? Thanks!,I just like to say that your website is absoulutely brilliant!!! Do you think my sites too brilliant ;) ? Thanks!

  • I am also having a problem using a few of the more advanced web services. I am trying to pull only users with a certain level of access to the site and just like Clay Fox:

    "When I preview the form with the data connection to this method autoloading however I get an error that the form tmeplate is invalid and an error message stating that the parameter loginName cannot be empty."

    If anyone knows how to rectify this problem or how I can store a value to this parameter before the data is queried, please let me know.

  • Hi, I publised my infopath form in Sharepoint portal server.Whenever my infopath form opens i need current logged user name of sharepoint server.How to get current logged user of sharepoint portal server? Please help me.


    Senthil Kumar D

  • Hello,
    Please help, I'd like to ask this: what format do I need to use so that the data in a field show's in a sharepoint list as an actual user?
    Just like the "Modified By" default column.
    I update the data as DOMAIN\user and it doesn't work.
    I update the data as and it doesn't work either.
    Do I have to define the XML elemente type as something special?
    Is there a special format to use? do I need to modify the XSL somehow?

  • Lucy! Please call me,Lucy! Please call me

  • Try this in 2007

    this.DataSources["DummyUsers"].CreateNavigator().InnerXml = this.DataSources["Users"].CreateNavigator().InnerXml;


  • Okay, I got the code to work but my drop down list box is blank. Why?

  • Okay, I got the code to work but my drop down list box is blank on preview. What is wrong?

  • [URL=] castello di [/URL] castello di [URL=] www eva henger it [/URL] www eva henger it [URL=] incontri italia [/URL] incontri italia [URL=] trenitalia it [/URL] trenitalia it [URL=] infermiere porche [/URL] infermiere porche [URL=] plug in nero [/URL] plug in nero [URL=] kiss the girl ashley tisdale [/URL] kiss the girl ashley tisdale [URL=] traduzioni on line [/URL] traduzioni on line [URL=] giocare online [/URL] giocare online [URL=] roma calzature [/URL] roma calzature [URL=] futurama xxx [/URL] futurama xxx [URL=] filmati porno [/URL] filmati porno [URL=] nomi [/URL] nomi [URL=] google fr [/URL] google fr [URL=] audio divx [/URL] audio divx [URL=] www goole com [/URL] www goole com [URL=] geogle earth [/URL] geogle earth [URL=] donne che cagano [/URL] donne che cagano [URL=] ranma 1 2 [/URL] ranma 1 2 [URL=] video pompino [/URL] video pompino [URL=] alessandra mastronardi nuda [/URL] alessandra mastronardi nuda [URL=] arcaton com [/URL] arcaton com [URL=] wwww google [/URL] wwww google [URL=] www giochi gratis it [/URL] www giochi gratis it [URL=] www mediaset premium it [/URL] www mediaset premium it [URL=] www cartoon network com [/URL] www cartoon network com [URL=] italiacercami com [/URL] italiacercami com [URL=] italia chiamami com [/URL] italia chiamami com [URL=] google hearth [/URL] google hearth [URL=] carta geografica [/URL] carta geografica [URL=] pics porno [/URL] pics porno [URL=] playstation gratis [/URL] playstation gratis [URL=] italiacercami [/URL] italiacercami [URL=] video porno sesso gratis gay [/URL] video porno sesso gratis gay [URL=] escort forum it [/URL] escort forum it [URL=] simona ventura nuda [/URL] simona ventura nuda [URL=] film porno [/URL] film porno [URL=] valentino rossi shop [/URL] valentino rossi shop [URL=] ranma hentay [/URL] ranma hentay [URL=] filmati di sesso [/URL] filmati di sesso [URL=] www calendari it [/URL] www calendari it [URL=] latino online [/URL] latino online [URL=] ampland it [/URL] ampland it [URL=] player wmv [/URL] player wmv [URL=] tim cellulari [/URL] tim cellulari [URL=] racconti cuckold [/URL] racconti cuckold [URL=] sex chat [/URL] sex chat [URL=] gioco scaricare [/URL] gioco scaricare [URL=] sesso donna matura [/URL] sesso donna matura [URL=] gogle it [/URL] gogle it [URL=] www lady sonia com [/URL] www lady sonia com [URL=] calciatori nudi [/URL] calciatori nudi [URL=] ciaoamigos it [/URL] ciaoamigos it [URL=] teen sex [/URL] teen sex [URL=] sito porno gratis [/URL] sito porno gratis [URL=] iomilu com [/URL] iomilu com [URL=] mondo convenienza [/URL] mondo convenienza [URL=] www film pornogratis donne mature it [/URL] www film pornogratis donne mature it [URL=] test concorso [/URL] test concorso [URL=] naked girls [/URL] naked girls

  • Hey all. For those of you that are about to pull your hair out from the ‘Unexpected XML declaration…..’ and other similar errors, I came up with what seems to be an acceptable solution.
    In my situation I wanted to pass some contact selector xml from my workflow association form to my task form. Then I wanted it to be usable in a dropdown box for the user to select one of the predetermined people.

    I accomplished this by:
    - Building xml string the task form secondary data source is expecting
    - Get the InnerXml of the root node. This may technically be invalid xml because of more than one root node but this should not matter.
    - Then pass the xml string though the ExtendedProperties[“MyXmlTaskData”]
    - On form loading event run the following code

    DataSource fromWorkflow = this.DataSources["ItemMetadata"];
    DataSource toForm = this.DataSources["ContactSelectorSecondaryDataSource"];

    string str = fromWorkflow.CreateNavigator().SelectSingleNode("/z:row/@ows_MyXmlTaskData", this.NamespaceManager).Value;

    if (!string.IsNullOrEmpty(str))
    XPathNavigator nav = toForm.CreateNavigator();
    nav.InnerXml = str;

    This seems to have done the trick for me. I hope it can help you!

    Best of luck!

Comments have been disabled for this content.