克隆共享点角色组 [英] Cloning a sharepoint rolegroup

查看:45
本文介绍了克隆共享点角色组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个 C# 应用程序来克隆 SharePoint MOSS2007 角色组(及其权限),但没有起点.

I'd like to write a C# application to clone a SharePoint MOSS2007 role group (and its permissions) in however don't have a starting point.

MOSS2007 似乎记录不足(就开发而言),尽管在谷歌上搜索了相当广泛的问题,但仍然不知道该开始尝试什么.我希望这里有人做过类似的事情和/或足够了解 SharePoint 库,以提供一个很好的参考点.

MOSS2007 seems quite under-documented (in terms of development) and despite googling the problem quite extensively still don't have any idea what to start trying. I was hoping somebody here had done something similar and/or knew the SharePoint library enough to provide a good reference point.

我真诚地为这个基本问题道歉,也没有提供更多信息 - 如果我还有其他事情我会的!

I sincerely apologise for the basic question and also not providing more information - if I had anything else I would!

推荐答案

当克隆"SharePoint 安全组时,首先不是关于组本身,而是关于权限.

when 'cloning' a SharePoint security group its first of all not about the group itself but about the permissions.

这些权限存储为 SPWeb 对象的角色分配.首先,您必须通过执行以下操作找到要克隆的组:

These permissions are stored as roleassignments to a SPWeb object. First you must find the group that you want to clone by doing:

SPGroup group = spWeb.Groups["name group"];

然后您必须使用此检索到的组来获取 SPWeb 对象上的角色分配.

Then you must use this retrieved group to get the roleassignments on the SPWeb object.

SPRoleAssignment ass = spWeb.RoleAssignments.GetAssignmentByPrincipal(group2);

然后您必须简单地创建一个新的 SPGroup 并将该组添加到角色分配并将角色分配添加到 Web 对象:

Then you must simply create a new SPGroup and add the group to the roleassignment and the roleassignment to the web object:

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();

在此之后,您应该拥有一个与原始组具有相同权限的新组.

After this you should have a new group with the same permissions as the original group.

如果您没有在 sharepoint 功能中执行上述操作,或者您可以从控制台应用程序中执行此操作.只需在 VS 中创建一个控制台应用程序并填充如下内容:

If you're not doing the above in a sharepoint feature or something you can do it from a console application. Just create a console application in VS and fill it with something like this:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.SharePoint;   
namespace ConsoleApplication 
{     
class Program     
{         
static void Main(string[] args)         
{             
    using (SPSite spSite = new SPSite("http://yoururl"))            
    {                 
          using (SPWeb spWeb = spSite.RootWeb)   
          {                     
            //perform the code to clone the group here
          }          
    }                  
 }    
 } 
}

这篇关于克隆共享点角色组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆