SPGroup 和SPUser的常用操作
来源:互联网 发布:交大慧谷 seo 编辑:程序博客网 时间:2024/05/22 08:20
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.AllUsers[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>0) { 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(";#") > 0) { str = str.Substring(str.LastIndexOf(";#") + 2); } 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("Group_Name", 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; }
判断当前用户是否存在该组
public bool IsUserInGroup(string groupName) { bool inGroup = false; try { SPGroup group = SPContext.Current.Web.Groups[groupName]; inGroup = group.ContainsCurrentUser; } catch (Exception ex) { // SharePoint throws an exception if the group indexer // is not a group the current user belongs to. inGroup = false; } return inGroup; }
- SPGroup 和SPUser的常用操作
- SPGroup 和SPUser的常用操作 (转)
- 使用 SharePoint 2007 进行安全性编程(SPUser,SPGroup,SPSiteGroups)
- SPUser的用法
- 获取组SPGroup的描述Description信息
- Sharepoint中得到spuser的方法
- 常用的数据库和数据库操作
- 常用的数据库和数据库操作
- CTime COleDateTime的常用操作和比较
- CTime COleDateTime的常用操作和比较
- 一些操作cookie和常用的JS
- RMAN常用的命令和操作
- Nsarray 和NSMutableArray 的常用基础操作
- git的常用操作指令和错误
- 单链表的创建和常用操作
- 线程的状态和常用操作
- 常用的gcc编译指令和操作
- redis的hash和常用操作
- sersync同步镜像网站
- 《Cocoa设计模式》读书笔记(2)
- 用Mozilla Firefox浏览器登陆Oracle EBS 11i (Oracle电子商务套件)的方法.
- 非BMP TIF格式图片上传 屏幕显示该图片
- 股市低迷或是FB IPO延期的真正原因
- SPGroup 和SPUser的常用操作
- java SSH2Ftp 上传 下载 多个文件
- 关于TreeSet的排序问题
- iOS 检测有没有安装其它应用
- java打开文件(Windows exe,应用文件exe,以及其他任何格式的文件)
- JAVA自动更新程序
- Web App和Native App 谁将是未来
- 常见内存错误
- Elastix 2.3 手机卡接入出现主叫unknow和呼入时等待时长较长后出现语音提示