[英]Application to copy a SharePoint Group
根据此条目: 克隆sharepoint角色组我正在尝试创建一个控制台应用程序来复制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);
我不一定需要有人陪我来解决这个问题(毕竟,这是一个学习练习)。 相反,你能不能帮助我理解我的思维过程在哪里落下以及我需要学习什么来纠正这个问题?
添加方法:First Param:新组名
第二个参数:所有者(SPUser对象)
第三个参数:组的默认用户(SPMember对象)。
第四个参数:新的组描述
从站点管理员新组
第一个参数就像Name TextBox
第二个参数和第三个参数就像是集团所有者的人选
第四个参数就像关于我的 RichTextBox
您已找到代码的正确问题。 当您调用以下方法时:
spWeb.SiteGroups.Add(groupName, user, user, groupDescription);
你忘了用户不应该是一个字符串而是一个真正的SPUser
对象。 如果获得SPUser
对象,则应该能够将新组添加到SPWeb / SPSite。
您可以使用以下方式获取用户对象:
SPUser spUser = spWeb.EnsureUser(loginName);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.