Reputation: 9910
I'd like to write a C# application to clone a SharePoint MOSS2007 role group (and its permissions) in however don't have a starting point.
MOSS2007 seems quite under-documented (in terms of development) and despite googling the problem quite extensively still don't have any idea what to start trying. I was hoping somebody here had done something similar and/or knew the SharePoint library enough to provide a good reference point.
I sincerely apologise for the basic question and also not providing more information - if I had anything else I would!
Upvotes: 3
Views: 593
Reputation: 922
When you want to edit, change or add groups remotely you can indeed use a webservice. The webservice you'll need it the usergroup.asmx. You can find the methods of this webservice by simply calling it in SharePoint.
So browse: http://MySharePointSite/_vti_bin/usergroup.asmx
This will give you a list of all the available methods of the service. Connecting to the webservice from an application can be done by:
http://msdn.microsoft.com/en-us/library/ms458094.aspx
and this tells you how to interact with the usergroup webservice:
http://msdn.microsoft.com/en-us/library/ms412944.aspx
Upvotes: 1
Reputation: 922
when 'cloning' a SharePoint security group its first of all not about the group itself but about the permissions.
These permissions are stored as roleassignments to a SPWeb object. First you must find the group that you want to clone by doing:
SPGroup group = spWeb.Groups["name group"];
Then you must use this retrieved group to get the roleassignments on the SPWeb object.
SPRoleAssignment ass = spWeb.RoleAssignments.GetAssignmentByPrincipal(group2);
Then you must simply create a new SPGroup and add the group to the roleassignment and the roleassignment to the web object:
spWeb.SiteGroups.Add(groupName, user, user, groupDescription);
SPGroup newGroup = spWeb.SiteGroups[groupName];
SPRoleAssignment roleAssignment = new SPRoleAssignment(newGroup);
//add role to web
spWeb.RoleAssignments.Add(roleAssignment);
spWeb.Update();
After this you should have a new group with the same permissions as the original group.
If you're not doing the above in a sharepoint feature or something you can do it from a console application. Just create a console application in VS and fill it with something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
using (SPSite spSite = new SPSite("http://yoururl"))
{
using (SPWeb spWeb = spSite.RootWeb)
{
//perform the code to clone the group here
}
}
}
}
}
Upvotes: 4