Dropdown of users in a active directory group

M

miaminemo

Guys -

I know I can write a web service to list all members within an AD
group, but does Infopath provide this functionality natively?

Any help or suggestions are appreciated.

Will
 
M

miaminemo

The boss isnt going to pay for software, but I appreciate the input.

Does anyone have a vb.net web service lying around to query for the
members of a specific AD group?

If not, looks like ill have to write one
 
D

David Dean

If you write your own web service, you can use the
SPUtility.GetPrincipalsInGroup() method in the Microsoft.SharePoint.Utilities
namespace to determine the list of users in a group (see
http://msdn2.microsoft.com/en-us/li...utilities.sputility.getprincipalsingroup.aspx):

Dim groupUsers As SPPrincipalInfo() =
SPUtility.GetPrincipalsInGroup(SPContext.Current.Web, "DOMAIN\group", 100,
False)

If the AD group has been added as a site user, you can use:

Dim users As SPUserCollection =
SPContext.Current.Web.Groups("DOMAIN\group").Users

You may need to use elevation of privilege (see
http://msdn2.microsoft.com/en-us/library/aa543467.aspx for info) if you run
into security issues when running as a non-admin user.
 
M

miaminemo

Thanks -

Ive got it up and working now - in case anyone else gets stuck here is
what I did -

Public Shared Function GetDirectoryEntry() As DirectoryEntry
Dim dirEntry As DirectoryEntry = New DirectoryEntry
dirEntry.Path = "LDAP://172.29.33.20/CN=Users;DC=NWIE"
dirEntry.Username = "nwie\smsclient_sfw"
dirEntry.Password = "GoBucks05"
Return dirEntry
End Function
Private Shared Function GetDirectoryObject() As DirectoryEntry
Dim oDE As DirectoryEntry
'oDE = New DirectoryEntry(ADFullPath, ADAdminUser,
ADAdminPassword, AuthenticationTypes.Secure)
oDE = New DirectoryEntry(ADFullPath)
Return oDE
End Function
Public Shared Function GetProperty(ByVal oDE As DirectoryEntry,
ByVal PropertyName As String) As String
If oDE.Properties.Contains(PropertyName) Then
Return oDE.Properties(PropertyName)(0).ToString()
Else
Return String.Empty
End If
End Function
Public Shared Function GetUsersinGroup(ByVal GroupName As String)
As DataSet
Dim dsUsers As New DataSet
Dim dirEntry As DirectoryEntry = GetDirectoryObject()
Dim dirSearch As New DirectorySearcher
dirSearch.SearchRoot = dirEntry
dirSearch.Filter = "(&(objectClass=group)(cn=" + GroupName +
"))"
Dim searchResults As SearchResult = dirSearch.FindOne()
Dim dtUser As DataTable = dsUsers.Tables.Add("Users")
dtUser.Columns.Add("UserName")
dtUser.Columns.Add("DisplayName")
dtUser.Columns.Add("EMailAddress")
Dim drUser As DataRow = dtUser.NewRow()
drUser("UserName") = "0"
drUser("DisplayName") = "(Not Specified)"
drUser("EMailAddress") = "(Not Specified)"
dtUser.Rows.Add(drUser)
If Not searchResults Is Nothing Then
Dim dirGroup As New DirectoryEntry(searchResults.Path)
Dim propCollection As PropertyCollection =
dirGroup.Properties
Dim n As Integer = propCollection("member").Count
For l As Integer = 0 To n - 1
Dim deUser As New DirectoryEntry(ADFullPath + "/" +
propCollection("member")(l).ToString())
Dim rwUser As DataRow = dtUser.NewRow()
rwUser("UserName") = GetProperty(deUser, "cn")
rwUser("DisplayName") = GetProperty(deUser,
"givenName") + " " + GetProperty(deUser, "sn")
rwUser("EMailAddress") = GetProperty(deUser, "mail")
dtUser.Rows.Add(rwUser)
deUser.Close()
Next
dirEntry.Close()
dirGroup.Close()
End If
Return dsUsers
End Function

Were using wss 2003, not wss 3.0 so i couldnt use the sharepoint
functionality.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top