Hi there,
I am trying to check the loggged in user is exsist in AD group(TestMF) or not in sharepoint online.But on rest api does not gives any sign of users.Pls suggest me any idea to find logged users exsist in AD group.
regards
Gowtham.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ronika JencyPosted Nov 17, 2019, 11:47 PM
Dinesh GabhanePosted Nov 17, 2019, 11:50 PM
First you can get the identity of the user which you want to know, then use the user’s token to log into the SharePoint, finally call SPGroup.ContainsCurrentUser for that user. The code is as follows:
using(SPWeb web=site.OpenWeb())
{
user=web.EnsureUser("domain\\username");
}
using (SPSite site1 = new SPSite("http://site/",user.UserToken))
In addition to that, you can also use SPWeb.IsCurrentUserMemberOfGroup to know whether the current user is a member of the specified group.
For more information about SPWeb.IsCurrentUserMemberOfGroup Method, please refer to the following articles:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.iscurrentusermemberofgroup.aspx
http://fabioscagliola.spaces.live.com/blog/cns!919F8FCDE3DC9AC4!195.entry