Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 复制SharePoint组的应用程序_C#_Sharepoint_Sharepoint 2007_Sharepoint Api - Fatal编程技术网

C# 复制SharePoint组的应用程序

C# 复制SharePoint组的应用程序,c#,sharepoint,sharepoint-2007,sharepoint-api,C#,Sharepoint,Sharepoint 2007,Sharepoint Api,根据以下条目:我正在尝试创建一个控制台应用程序来复制SharePoint组,包括其权限 根据Tjassens的回答,我得出以下结论: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; namespace REGroupCopy { class Program { static voi

根据以下条目:我正在尝试创建一个控制台应用程序来复制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);
我不一定需要有人来帮我解决这个问题(毕竟,这是一个学习练习)。相反,请您帮助我了解我的思维过程在哪里下降,以及我需要学习什么来纠正这一点?

添加方法: 第一个参数:新的组名

第二个参数:所有者(SPUser对象)

第三个参数:组的默认用户(SPMember对象)

第四个参数:新的组描述

来自站点管理员新组

第一个参数类似于NameTextBox

第二个参数和第三个参数类似于组所有者


第四个参数类似于关于我RichTextBox

您已经找到了代码的正确问题。调用以下方法时:

spWeb.SiteGroups.Add(groupName, user, user, groupDescription); 
您忘记了用户不应该是字符串,而应该是实际的
SPUser
对象。如果您获得
SPUser
对象,您应该能够将新组添加到SPWeb/SPSite

您可以使用以下方法获取用户对象,例如:

SPUser spUser = spWeb.EnsureUser(loginName);

你能举个例子吗?另外,我理想情况下希望在控制台应用程序中完成所有这些工作(如果可能的话)-这似乎与此不符?