根据此条目:克隆共享点角色组我正在尝试创建一个控制台应用程序来复制 SharePoint 组,包括其权限。
根据 Tjassens 的回答,我得出以下结论:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace REGroupCopy
{
class Program
{
static void Main(string[] args)
{
using (SPSite spSite = new SPSite("http://dev"))
{
using (SPWeb spWeb = spSite.RootWeb)
{
// first we find the group that we want to clone
SPGroup group = spWeb.Groups["Test Group"];
// then we use this retreived group to get the roleassignments on the SPWeb object
SPRoleAssignment ass = spWeb.RoleAssignments.GetAssignmentByPrincipal(group);
string groupName = "Test Group 2"; // group to create
string groupDescription = "Group created by REGroupCopy";
string user = "michael";
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();
}
}
}
}
}
不幸的是,我认为我没有正确理解所有内容。具体来说,我认为这些行是不正确的,但我不确定它们应该是什么:
string groupName = "Test Group 2"; // group to create
string groupDescription = "Group created by REGroupCopy";
string user = "michael";
spWeb.SiteGroups.Add(groupName, user, user, groupDescription);
我不一定需要有人来帮我解决这个问题(毕竟,这是一个学习练习)。相反,您能否帮助我了解我的思维过程在哪里失败以及我需要学习什么来纠正这个问题?