Dynamically Add to Drop-Down in Infopath using a Web Service May 7, 2008
Posted by spunkyvt in Programming, Sharepoint.Tags: drop-down, InfoPath, Sharepoint, web service
add a comment
OK. After banging my head about for hours now, I have finally found a solution. This is going to use the permissions built into Sharepoint. It will list out all the groups that have permissions to a form library.
First you need to make an xml file.
Create an xml file with this info in it. Name it Permiss.xml.

Drag a drop-down box onto the infopath form. Click on DataConnections under tools. Click the add button. Create a new connection and set it to Receive Data. Click the Next and choose XML Document. Browse to the file location and choose the Permiss.xml file. Cick next and Make sure that Automatically retrieve data when form is opened is checked.
Right Click on the Drop-Down List Box properties. Click on the Look up values from an external data source. In the Data source drop down pick permiss. Click on button beside Entries and choose the permissions node. Click OK. Next click button beside Value and choose MemberID. Click OK. Click the button beside Display name and choose GroupName. Finally all done there.
Now onto the code behind.
Add a web reference to the http://localhost/_vti_bin/permissions.asmx
Call it permission.
In the FormEvents_loading method add this code
permissions.Permissions perm = new GFill.permissions.Permissions();
perm.Credentials = System.Net.CredentialCache.DefaultCredentials;
String FormName = “youLibrary”
XmlNode nod = perm.GetPermissionCollection(FormName, “List”);
XPathNavigator sitepermiss = DataSources["permiss"].CreateNavigator() ;
XmlNamespaceManager umanager = new XmlNamespaceManager(sitepermiss.NameTable);
umanager.AddNamespace(“ns1″, “http://schemas.microsoft.com/sharepoint/soap/directory/”);
XPathNavigator f1 = sitepermiss.SelectSingleNode(“//ns1:GetPermissionCollection/ns1:Permissions”, umanager);
XPathNavigator g = nod.CreateNavigator().SelectSingleNode(“//ns1:Permissions”, umanager);
f1.ReplaceSelf(g);
If all goes well this is all you should need in order to dynamically fill those drop-downs. I have to vent for a second. This is way harder than it should be. Something this simple and trivial should not have been this complicated to implement. Kudos Microsoft. You win the Rube Goldberg award for the day. I hope this will save someone else numerous hours.
