As per subject, tried many examples that none seem to work.
Simply I need to check if the current user is a member of a certain
Active Directory group?
Firstly, you're in the wrong newsgroup. Please post ActiveDirectory
questions in the ActiveDirectory newsgroup: microsoft.public.adsi.general
However, the following function returns a List<string> of the groups
that a user belongs to:
List<string> GetGroupsForUser(string pstrUser)
{
List<string> lstGroups = new List<string>();
using (DirectorySearcher objDS = new
DirectorySearcher("objectCategory=User"))
{
objDS.Filter = "(SAMAccountName=" + pstrUser + ")";
using (DirectoryEntry objUser = new
DirectoryEntry(objDS.FindOne().Path))
{
PropertyCollection colProperties = objUser.Properties;
PropertyValueCollection colPropertyValues =
colProperties["memberOf"];
foreach (string strGroup in colPropertyValues)
{
lstGroups.Add(strGroup.ToLower());
}
}
}
return lstGroups;
}
Then, all you have to do is check whether the group you're interested in
is contained in the generic...
Alternatively, as AD is navigational, not relational, start with the
group and query AD for its members...