We are running the site on form authentication. when the user is approved by the admin we have add the approved user in SharePoint group.
So to add the user to sharepoint group user the following code :
SPUser spUser;
string accountName="AccountName";
string sGruupName="GroupName;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite spSite = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb obSPWeb = spSite.RootWeb)
{
if (!accountName.Contains(":"))
{
accountName = Membership.Provider.Name + ":" + accountName;
}
spUser = obSPWeb.EnsureUser(accountName);
SPGroup spGroup = obSPWeb.SiteGroups[sGruupName];
spGroup.AddUser(spUser);
}
}
});