Sharing SharePoint

Always a rookie in the SharePoint World

  • Follow me on Twitter

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

  • Blog Stats

    • 60,367 hits
  • Advertisements

Get User Collection from a Sharepoint Group

Posted by Jessica Wang on March 25, 2008

I have been working on getting a drop down list in Infopath to be populated with users of a Sharepoint Group. You can’t connect directly to the drop drop list, so you will need to create 2 data sources, 1 to the web service and another xml file with dummy data which will be replace be information from the web service.

1. Create a data connection to the web service using the data connection wizard.


Data Connection

Click next and select GetUserCollectionFromGroup

Enter Sample data, which is the name of the group which you wish to get data from.

2. You will need dummy data to be connected to the drop down list first. There are 2 dummy users in the xml, it tells infopath that it is repeating.


<?xml version=”1.0″ encoding=”utf-8″ ?>

 <dfs:myFields xmlns:dfs=”; xmlns:s0=”; xmlns:my=”; xmlns:soap=”; xmlns:xsi=”; xmlns:xsd=””&gt;    <dfs:queryFields>        <s0:GetUserCollectionFromGroup>        </s0:GetUserCollectionFromGroup>    </dfs:queryFields>    <dfs:dataFields>        <GetUserCollectionFromGroupResponse xmlns=””&gt;            <GetUserCollectionFromGroupResult>                <GetUserCollectionFromGroup>                    <Users>                        <User ID=”1″ Sid=”S-1-5-21-3593225548-2099380924-3969701235-500″ Name=”User1″ LoginName=”login1″ Email=”” Notes=”” IsSiteAdmin=”False” IsDomainGroup=”False”/>                        <User ID=”2″ Sid=”S-1-5-21-3593225548-2099380924-3969701235-1145″ Name=”User2″ LoginName=”login2″ Email=”” Notes=”” IsSiteAdmin=”False” IsDomainGroup=”False”/>                    </Users>                </GetUserCollectionFromGroup>            </GetUserCollectionFromGroupResult>        </GetUserCollectionFromGroupResponse>    </dfs:dataFields></dfs:myFields>

Save the dummydata.xml and connect it via the Data Connection Wizard as well.

3. Link the drop down list to the dummydata.xml


4. You will need to go to the loading event of the infopath form, which you can get to by going to Tools>Programming>Loading Event

It will open up Visual studio. Within the Loading Event, you will need the following piece of code.

public void FormEvents_Loading(object sender, LoadingEventArgs e)


//Dummy Data

//get an XPathNavigator to our webservice method                                                XPathNavigator dutyManagerDummy = this.DataSources[“DutyManagerListDummyData”].CreateNavigator();

//create the XmlNamespaceManager that will allow us to navigate the xml
umanager = new XmlNamespaceManager(dutyManagerDummy.NameTable);



//get the node that contains all the users from dummy data
DutyManagerListDummyDataName = dutyManagerDummy.SelectSingleNode(“/dfs:myFields/dfs:dataFields/tns:GetUserCollectionFromGroupResponse/tns:GetUserCollectionFromGroupResult/tns:GetUserCollectionFromGroup/tns:Users”, umanager);

//Actual Data

//get an XPathNavigator to our webservice method                                                 XPathNavigator dutyManager = this.DataSources[“GetUserCollectionFromGroup”].CreateNavigator();

//create the XmlNamespaceManager that will allow us to navigate the xml
dmanager = new XmlNamespaceManager(dutyManager.NameTable);



//get the node that contains all the users from the call to the web service
dusers = dutyManager.SelectSingleNode(“/dfs:myFields/dfs:dataFields/tns:GetUserCollectionFromGroupResponse/tns:GetUserCollectionFromGroupResult/tns:GetUserCollectionFromGroup/tns:Users”, umanager);


                             //replace the dummy information from the information from the web service


                         catch(NullReferenceException ee){}


Run the preview and you should see the actual data instead of the dummy information.


9 Responses to “Get User Collection from a Sharepoint Group”

  1. Eric Smith said

    Handy post. I happened to find myself with a very similar problem last week. What I really need is a list of domain users in various AD groups. MOSS 2007 can clearly find this information itself but will it make it available as it does its own groups?

    Hi Eric,

    Sharepoint will allow you to add domain/users from various AD groups into Sharepoint Groups.
    However, using the method that I stated, it will just display domain/users and not the list of users in the domain/users

    Jessica Wang

  2. You should specify that this solution only works with InfoPath 2007. And you also need Microsoft Visual Studio Tools for Applications (VSTA). This is a useless solution for InfoPath 2003. And if you want to stay confined to script instead of code.

    but other than that, I really like this post, I will definitely use it if a client has the essentials needed to make this solution work.


  3. kevin said

    an excellant Posting a question though, can you have multiple drop downs on the same pages, i am having errors being able to have more then one on a form

  4. chris said

    Hi Jessica,

    I have the same problem than Kevin, do you have an idea?

    Have a nice day!

  5. Henry Min said

    Hi Jessica,

    Is there any way to pass groupname from the form control (value from text box) to populate user list?


  6. DooriaGam said

    well.. it’s like I thought!

  7. Meri said

    I’m getting an “unspecified error” when trying to add the XML file as a data connection. Has anyone else encountered this and come up with a solution?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: