Sharing SharePoint

Always a rookie in the SharePoint World

  • Follow me on Twitter

  • Blog Stats

    • 61,910 hits

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.

<http://servername/_vti_bin/UserGroup.asmx?WSDL>

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.

DummyData.xml

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

 <dfs:myFields xmlns:dfs=”http://schemas.microsoft.com/office/infopath/2003/dataFormSolution&#8221; xmlns:s0=”http://schemas.microsoft.com/sharepoint/soap/directory/&#8221; xmlns:my=”http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-03-16T06-17-54&#8243; xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt;    <dfs:queryFields>        <s0:GetUserCollectionFromGroup>        </s0:GetUserCollectionFromGroup>    </dfs:queryFields>    <dfs:dataFields>        <GetUserCollectionFromGroupResponse xmlns=”http://schemas.microsoft.com/sharepoint/soap/directory/”&gt;            <GetUserCollectionFromGroupResult>                <GetUserCollectionFromGroup>                    <Users>                        <User ID=”1″ Sid=”S-1-5-21-3593225548-2099380924-3969701235-500″ Name=”User1″ LoginName=”login1″ Email=”user1@users.com” Notes=”” IsSiteAdmin=”False” IsDomainGroup=”False”/>                        <User ID=”2″ Sid=”S-1-5-21-3593225548-2099380924-3969701235-1145″ Name=”User2″ LoginName=”login2″ Email=”user2@users.com” 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

dropdownlist.png

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
XmlNamespaceManager
umanager = new XmlNamespaceManager(dutyManagerDummy.NameTable);

umanager.AddNamespace(“dfs”, http://schemas.microsoft.com/office/infopath/2003/dataFormSolution);

umanager.AddNamespace(“tns”, http://schemas.microsoft.com/sharepoint/soap/directory/);

//get the node that contains all the users from dummy data
XPathNavigator
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
XmlNamespaceManager
dmanager = new XmlNamespaceManager(dutyManager.NameTable);

dmanager.AddNamespace(“dfs”, http://schemas.microsoft.com/office/infopath/2003/dataFormSolution);

dmanager.AddNamespace(“tns”, http://schemas.microsoft.com/sharepoint/soap/directory/);

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

                         try{               

                             //replace the dummy information from the information from the web service
                             DutyManagerListDummyDataName.ReplaceSelf(dusers);
           

                            }           

                         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
    Example:
    domain/users
    domain/guests
    sydney/users
    melbourne/admin

    Cheers,
    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.

    Juan

  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!
    Chris

  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?

    Thanks,
    Henry

  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 comment