Saturday, 1 March 2014

Check the current Login user in sharepoint Group using c#

Share it Please
 
SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                  
                    SPWeb theSite = SPControl.GetContextWeb(Context);
                    SPUser theUser = theSite.CurrentUser;
                    string CurrentUserLoginName = theUser.LoginName;
                    string siteUrl = SPContext.Current.Web.Url;
                    using (SPSite site = new SPSite(siteUrl))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            SPGroupCollection groupCollection = web.SiteGroups;
                            foreach (SPGroup group in groupCollection)
                            {
                                SPUserCollection userCollection = group.Users;
                                string GroupName = group.LoginName;
                                if (GroupName == GrpName)
                                {
                                    foreach (SPUser user in userCollection)
                                    {
                                        string UserName = user.LoginName;
                                        if (UserName == CurrentUserLoginName)
                                        {
                                          
                                        }
                                    }
                                }
                            }

                        }
                    }
                });

No comments:

Post a Comment

Followers

Follow The Author