SPGroup 和SPUser的常用操作
http://www.cnblogs.com/gzh4455/archive/2012/03/26/2417854.html
private bool RemoveUserFromGroup(string sGoupName, string sUserLoginName)
{
bool res = false;
try
{
SPWeb web = SPContext.Current.Web;
SPGroup oGroup = web.SiteGroups[sGoupName];
SPUser oUser = GetSPUser(sUserLoginName);
if (oUser != null)
{
web.AllowUnsafeUpdates = true;
oGroup.RemoveUser(oUser);
oGroup.Update();
res = true;
web.AllowUnsafeUpdates = false;
}
}
catch (Exception ex)
{
string sMessage = ex.Message;
//throw;
}
return res;
}
private bool RemoveUserFromGroup(SPGroup oGroup, SPUser oUser)
{
bool res = false;
try
{
SPWeb web = SPContext.Current.Web;
if (oUser != null&&oGroup!=null)
{
web.AllowUnsafeUpdates = true;
oGroup.RemoveUser(oUser);
oGroup.Update();
res = true;
web.AllowUnsafeUpdates = false;
}
}
catch (Exception ex)
{
string sMessage = ex.Message;
//throw;
}
return res;
}
private SPUser GetSPUser(string sLoginName)
{
SPUser oUser = null;
try
{
if (!string.IsNullOrEmpty(sLoginName))
{
oUser = SPContext.Current.Web.EnsureUser(sLoginName);
}
}
catch (Exception ex)
{
string sMessage = ex.Message;
}
return oUser;
} private void RemoveUser(string sLoginName)
{
SPUser oUser = GetSPUser(sLoginName);
if (oUser!=null)
{
SPGroupCollection groups = oUser.Groups;
if (groups!=null&&groups.Count>)
{
foreach (SPGroup g in groups)
{
RemoveUserFromGroup(g, oUser);
}
}
}
} private bool AddUserIntoGroup(string sGroupName, string sUserLoginName)
{
bool res = false;
try
{
SPWeb web = SPContext.Current.Web;
web.AllowUnsafeUpdates = true;
SPGroup oGroup = web.SiteGroups[sGroupName];
SPUser oUser = GetSPUser(sUserLoginName);
if (oUser != null)
{
oGroup.AddUser(oUser);
oGroup.Update(); res = true;
}
web.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
string sMessage = ex.Message;
//throw;
}
return res;
} private string FilterSPUserString(string str)
{
if (string.IsNullOrEmpty(str))
{
return str;
}
if (str.IndexOf(";#") > )
{
str = str.Substring(str.LastIndexOf(";#") + );
}
return str;
} private bool CreateSiteGroup(string sGroupName, string sGroupDescription)
{
bool res = false;
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
{
oWebsiteRoot.AllowUnsafeUpdates = true;
SPGroupCollection collGroups = oWebsiteRoot.SiteGroups;
string sLoginName = SPContext.Current.Web.CurrentUser.LoginName;
SPUser oUser = oWebsiteRoot.Users[sLoginName];
SPMember oMember = oWebsiteRoot.Users[sLoginName];
collGroups.Add(sGroupName, oMember, oUser, "Description");
oWebsiteRoot.AllowUnsafeUpdates = false;
res = true;
}
return res;
}
/// <summary>
/// 给组赋权限
/// </summary>
/// <param name="sGroupName"></param>
/// <param name="sPermissionLever"></param>
/// <returns></returns>
private bool SetGroupPermission(string sGroupName, string sPermissionLever)
{
bool res = false;
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
{
oWebsiteRoot.AllowUnsafeUpdates = true;
SPRoleAssignment roleAssignment = new SPRoleAssignment(oWebsiteRoot.SiteGroups[sGroupName]);
roleAssignment.RoleDefinitionBindings.Add(oWebsiteRoot.RoleDefinitions[sPermissionLever]);
oWebsiteRoot.Update();
oWebsiteRoot.AllowUnsafeUpdates = false;
res = true;
}
return res;
} private void DeleteSiteGroup(SPWeb web, string groupName)
{
web.AllowUnsafeUpdates = true;
SPGroupCollection groups = web.SiteGroups;
groups.Remove(groupName);
web.Update();
web.AllowUnsafeUpdates = false;
}
SPGroup 和SPUser的常用操作的更多相关文章
- SharePoint 2013 新功能探索 之 SPGroup、SPUser 事件处理程序 还要继续改进
曾几何时,想要获取SPGroup Add及SPUserAdd事件,在网上查找各种方法,都没有找到相对应的解决办法,如今在VS 2013 Preview版本 提供了 SPSecurityEventRec ...
- 【三】用Markdown写blog的常用操作
本系列有五篇:分别是 [一]Ubuntu14.04+Jekyll+Github Pages搭建静态博客:主要是安装方面 [二]jekyll 的使用 :主要是jekyll的配置 [三]Markdown+ ...
- php模拟数据库常用操作效果
test.php <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); ...
- Mac OS X常用操作入门指南
前两天入手一个Macbook air,在装软件过程中摸索了一些基本操作,现就常用操作进行总结, 1关于触控板: 按下(不区分左右) =鼠标左键 control+按下 ...
- mysql常用操作语句
mysql常用操作语句 1.mysql -u root -p 2.mysql -h localhost -u root -p database_name 2.列出数据库: 1.show datab ...
- nodejs配置及cmd常用操作
一.cmd常用操作 1.返回根目录cd\ 2.返回上层目录cd .. 3.查找当前目录下的所有文件dir 4.查找下层目录cd window 二.nodejs配置 Node.js安装包及源码下载地址为 ...
- Oracle常用操作——创建表空间、临时表空间、创建表分区、创建索引、锁表处理
摘要:Oracle数据库的库表常用操作:创建与添加表空间.临时表空间.创建表分区.创建索引.锁表处理 1.表空间 ■ 详细查看表空间使用状况,包括总大小,使用空间,使用率,剩余空间 --详细查看表空 ...
- python 异常处理、文件常用操作
异常处理 http://www.jb51.net/article/95033.htm 文件常用操作 http://www.jb51.net/article/92946.htm
- byte数据的常用操作函数[转发]
/// <summary> /// 本类提供了对byte数据的常用操作函数 /// </summary> public class ByteUtil { ','A','B',' ...
随机推荐
- Arc077_E Guruguru
传送门 题目大意 有$m$个点编号从小到大按照顺时针编成了一个环,有一枚棋子,每次移动可以选择顺时针移动到下一个或者直接移动到编号为$x$的点,现在有$n-1$次数操作,第$i$次要把棋子从第$A_i ...
- HDU5446 Unknown Treasure(组合数膜合数-->Lucas+中国剩余定理)
>On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown ...
- dbcc练习1
dbcc tranceon(2588,3604) dbcc ind() dbcc page()
- pytorch--cpu与gpu load时相互转化
pytorch------cpu与gpu load时相互转化 torch.load(map_location=)学习 将gpu改为cpu时,遇到一个报错:RuntimeError: Attemptin ...
- Swift中的参数内部名称和外部名称
1.什么是参数的内部名称和外部名称? struct Color { let red, green, blue: Double init(red redColor: Double,green green ...
- bash批量处理
[root@azure_dbm1_s1 scripts]# more slave_1062_stop.sh #/bin/bash slave_num=`mysql -e "show slav ...
- Azure上部署Barracuda WAF集群 --- 1
公有云上的第一层防护,一般要采用Proxy模式的安全设备. 梭子鱼的WAF是最早支持Azure China公有云的安全设备. 本文记录了在Azure上安装部署Barracuda的过程.下面就是安装部署 ...
- openStack kvm 虚拟机CPU颗粒化控制
前一篇理解cpu topology对CPU Topology进行了学习总结,这里想总结下OpenStack下vCPU与pCPU常用的的绑定方式. 在尝试这些绑定之前,尤其是处理NUMA架构时还是建议看 ...
- linux-java环境安装以及ssh
1 下载Java8 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2 使用 ...
- 16_点击事件第三种写法_activity实现接口
第一种写法是有名内部类,第二种写法是匿名内部类,第三种写法是MainActivity实现接口OnClickListener.直接让MainActivity实现了OnClickListener这个接口. ...