3

このエントリに従って: 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);

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

4

2 に答える 2

1

Add method : First Param : 新しいグループ名

2 番目のパラメーター: 所有者 (SPUser オブジェクト)

3 番目のパラメーター: グループの既定のユーザー (SPMember オブジェクト)。

4 番目のパラメーター: 新しいグループの説明

サイト管理者から 新しいグループ

最初のパラメータはName TextBoxのようなものです

2 番目のパラメータと 3 番目のパラメータは、グループ オーナーのピープル ピッカーのようなものです

4番目のパラメータは私についてRichTextBoxのようなものです

于 2012-07-19T08:06:35.077 に答える
1

コードに正しい問題が見つかりました。次のメソッドを呼び出す場合:

spWeb.SiteGroups.Add(groupName, user, user, groupDescription); 

ユーザーは文字列ではなく、実際のSPUserオブジェクトであることを忘れていました。オブジェクトを取得するSPUserと、新しいグループを SPWeb/SPSite に追加できるはずです。

たとえば、次を使用してユーザーオブジェクトを取得できます。

SPUser spUser = spWeb.EnsureUser(loginName);
于 2012-07-24T09:27:15.477 に答える