Important Note : This will only work for InfoPath Forms Services, not for InfoPath clients

 

Useful code below to check the membership of Active Directory groups for the current user.
For this you need to import the .net library System.DirectoryServices and change the web.config for sharepoint as commented in the code below…
As a warning, there tends to be multiple web.config files on a SharePoint server so make sure you get the correct one for your site, it should be in the root of your site. eg: c:\intepub\wwwroot\web.config

 

public Boolean isMemberInADGroup(string adGroup)
{

// Checks the active directory group membership of the
// current user to the specified group
Boolean retVal = false;

// requires the following lines in web.config
// <authentication mode=”Windows”>
// <rolemanager enabled=”true” defaultprovider=”AspNetWindowsTokenRoleProvider”>

string[] members = Roles.GetRolesForUser();
foreach (string role in members)
{

if (role == adGroup)
{

retVal = true;
break;

}

}

return retVal;
}