using
System;
System.Collections.Generic;
System.Linq;
System.Text;
Microsoft.SharePoint;
namespace
CopyUsersBetweenGroupsInSharepointByRR
{
class
Program
static
void
Main(
string
[] args)
Console.WriteLine(
"This tool will copy the users from one group to another group"
);
"Please enter the URL of the site where your groups are available"
String siteUrl = Console.ReadLine();
(SPSite site =
new
SPSite(siteUrl))
try
SPWeb web = site.OpenWeb();
"Please enter the name of the source group"
String sourceGroupName = Console.ReadLine();
"Please enter the name of the destination group"
String destinationGroupName = Console.ReadLine();
SPGroup sourceGroup = web.Groups[sourceGroupName];
SPGroup destinationGroup = web.Groups[destinationGroupName];
SPUserCollection sourceUsers = sourceGroup.Users;
SPUserInfo[] sourceUserInfoArray =
SPUserInfo[sourceUsers.Count];
for
(
int
i = 0; i < sourceUsers.Count; i++)
sourceUserInfoArray[i] =
SPUserInfo();
sourceUserInfoArray[i].LoginName = sourceUsers[i].LoginName;
sourceUserInfoArray[i].Name = sourceUsers[i].Name;
}
destinationGroup.Users.AddCollection(sourceUserInfoArray);
destinationGroup.Update();
web.Update();
"Operation Completed Successfully"
Console.ReadLine();
catch
(Exception e)
Console.WriteLine(e.Message);
Richard Mueller edited Revision 3. Comment: Removed (en-US) from title, changed tag "SPS 2010" to "SharePoint 2010"
Horizon_Net edited Revision 1. Comment: added language tags
Gokan Ozcifci edited Revision 2. Comment: Title and minor errors! great article