//Add User in SharePoint Groups
public void addUserToGroup(string groupName, string useName)
{
string strUrl = "http://MySites:9091/";
using (SPSite site = new SPSite(strUrl))
{
using (SPWeb web = site.OpenWeb())
{
try
{
web.AllowUnsafeUpdates = true;
SPUser spUser = web.EnsureUser[userName];
if (spUser != null)
{
SPGroup spGroup = web.Groups[groupName];
if (spGroup != null)
spGroup.AddUser(spUser);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
web.AllowUnsafeUpdates = false;
}
}
}
}
ensure that user have permission to execute this method.
Helpful Link and Ref:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.ensureuser.aspx
http://msdn.microsoft.com/en-us/library/office/ms414400.aspx
http://gallery.technet.microsoft.com/office/Bulk-remove-Unique-bddd8764
Showing posts with label SSOM. Show all posts
Showing posts with label SSOM. Show all posts
SharePoint Add Users To SharePoint Group
Saturday, December 7, 2013
Posted by Usama Wahab Khan at 2:49 PM 0 comments
Labels: Share Point, SharePoint 2010, SSOM
Subscribe to:
Posts (Atom)