根据这篇文章:复制SharePoint角色组,我正在尝试创建一个控制台应用程序来复制一个SharePoint群组,包括其权限。
根据Tjassens的答案,我得到了以下结果:
根据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);
我并不一定需要有人来帮我修复这个问题(毕竟,这是一次学习练习)。相反,你能否帮我理解我的思考过程出了什么问题,以及我需要学习哪些知识来纠正这个问题?