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',' ...
随机推荐
- CF221C Circling Round Treasures
题目大意 给定一个$n\times m$的网格$(n,m\leq 20)$,每个格子都是$S\space \#\space B\space x\space .$中第一个. $S$表示起点,保证有且仅有 ...
- python之路-进程
博客园 首页 新随笔 联系 管理 订阅 随笔- 31 文章- 72 评论- 115 python之路——进程 阅读目录 理论知识 操作系统背景知识 什么是进程 进程调度 进程的并发与并行 ...
- uoj problem 21 缩进优化
题目: 小O是一个热爱短代码的选手.在缩代码方面,他是一位身经百战的老手.世界各地的OJ上,很多题的最短解答排行榜都有他的身影.这令他感到十分愉悦. 最近,他突然发现,很多时候自己的程序明明看起来比别 ...
- jQuery DataTables 使用手册(精简版)
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/5182940.html 前排提醒,这个插件能不用就不用,那么多好的插件等着你,为什么要用它呢?就算用easyui的 ...
- 一步一步学RenderMonkey
http://blog.csdn.net/tianhai110/article/details/5668832 转载请注明出处:http://blog.csdn.net/tianhai110/ 网上一 ...
- MaCrea Lit Sphere maps
http://www.zbrushcentral.com/showthread.php?92157-MaCrea-Material-Creation-Tool 这边提供几个可以获取MatCap贴图的网 ...
- Oracle 12c 多租户 CDB 与 PDB之 shared undo 与 Local undo 切换
undo 在12C R1版本中只支持Global Shared Undo模式, 所有container共享一个UNDO表空间, 目前保留这种模式只是为了升级过渡, 在12C R2引入了PDB Loca ...
- MySQL读取各个my.cnf配置文件的先后顺序是:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 其他自定义路径下的my.cnf,例如:/data/mysql/y ...
- Poj_1004_FinancialManagement
一.Description Larry graduated this year and finally has a job. He's making a lot of money, but someh ...
- 我的SIP开发之路
http://hi.baidu.com/ltlovelty/blog/item/837baf1ece7fc6f11ad57647.html 经过对SIP协议和开源协议栈快半年的研究,我现在终于有点入门 ...