Problem: Currently working on a tool that one piece (the one I need help with) is having issues adding users to a specified SharePoint group. I am getting a legitimate SPUser but when I try to add that SPUser to the SPGroup it throws an error whenever that SPUser is an AD SPUser as opposed to one from the Forms-Based Authentication.
Expand|Select|Wrap|Line Numbers
- protected void AddUserToGroup(string strUserName)
- {
- SPWeb oWeb = SPContext.Current.Web;
- SPUser oUser = getSPUser(strUserName);
- if (oUser != null)
- {
- oWeb.AllowUnsafeUpdates = true;
- SPGroup oCurrentGroup = oWeb.Groups[gstrListGroup];
- lblStatus.Text += oUser.Name + ": ";
- try
- {
- oCurrentGroup.AddUser(oUser);
- lblStatus.Text += "Complete<br>";
- }
- catch (Exception)
- {
- lblStatus.Text += "Error occured. Please check the name or add the user via the Sharepoint Group<br>";
- }
- finally
- {
- oCurrentGroup.Update();
- }
- oWeb.AllowUnsafeUpdates = false;
- }
- }
Could this possibly be a case where if the user may no longer exist in AD but still has a SharePoint account that they may be throwing this error?