このエントリに従って: 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);
必ずしも誰かが来て、これを修正してくれる必要はありません (結局のところ、これは学習課題です)。代わりに、私の思考プロセスが落ち込んでいる場所と、これを修正するために何を学ぶ必要があるかを理解するのを手伝ってくれませんか?