sharepoint 判断用户是否存在某个组中三种方法
生活随笔
收集整理的這篇文章主要介紹了
sharepoint 判断用户是否存在某个组中三种方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、思路:查找用戶所有的組來匹配是否在特定的組(推薦)
不用擔心組不存在而報錯。
public static bool IsUserMemberOfGroup(SPUser user, string groupName){bool result = false;if (!String.IsNullOrEmpty(groupName) && user != null){foreach (SPGroup group in user.Groups){if (group.Name == groupName){// found itresult = true;break;}}}return result;}2、思路:查找特定組中是否有該用戶
如果組不存在會報錯?
public bool IsExitUser(SPWeb web, string loginname, string groupname){try{foreach (SPUser userlist in web.SiteGroups[groupname].Users){if (userlist.LoginName.ToString().ToLower() == loginname.ToLower())return true;}return false;}catch (Exception){throw;}}3、通過jquery判斷,需要借助SPServices?
function IsGroupMember(groupname) {//Checks user group membership to see if the current user is a member of "groupname"var booGroup = new Boolean(false);$().SPServices({operation: "GetGroupCollectionFromUser",userLoginName: thisUserAccount,async: false,webURL: "weburl",completefunc: function(xData, Status) {if ($(xData.responseXML).find("Group[Name='" + groupname + "']").length == 1) {booGroup = true;}}});return booGroup;}var thisUserAccount = $().SPServices.SPGetCurrentUser({fieldName: "Name",debug: false});調用的方式
if(IsGroupMember("用戶組名稱")==true){//您的代碼 }如果直接,代碼不起作用。
if(IsGroupMember("用戶組名稱")){//您的代碼 }?
?
?
轉載于:https://www.cnblogs.com/lrforever/p/3779431.html
總結
以上是生活随笔為你收集整理的sharepoint 判断用户是否存在某个组中三种方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOS 安装Python 3.52
- 下一篇: php如何封装类内乡通南阳的_PHP类(