I recently had a requirement where a user had to be added to a group as part of a SharePoint 2007 Workflow but the users accounts were stored in a SQLMembershipProvider and LDAPMembershipProvider as opposed to a Windows Domain.
The trick is you have to append the name of your provider to the users login for SharePoint to recognize the account. Normally you would use the DOMAIN\LOGIN syntax for users belonging to the AD.
string _userAccount = Membership.GetUser().UserName;
string _groupName = “Members”;
string _providerName = Membership.GetUser().ProviderName;
string _usernameWithProvider = String.Format("{0}:{1}", _providerName, _userAccount);
using (SPWeb currentTeamSite = workflowProperties.Web)
{
SPGroup spGroup = currentTeamSite.SiteGroups[_groupName];
spGroup.AddUser(_usernameWithProvider, Membership.GetUser().Email, Membership.GetUser().Email, "Added to group via SharePoint Workflow");
}
You do the same thing for subscribing to Alerts as well:
SPList list = currentTeamSite .Lists[0];
SPUser spUser = currentTeamSite .Users[_usernameWithProvider];
spUser.Alerts.Add(list, SPEventType.All, SPAlertFrequency.Immediate);
No comments yet... Be the first to leave a reply!