Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

April 24, 2014

SharePoint how to check user, CurrentUser is in perticuler site group

You wants to check if CurrentUser or particular User / SPUser is present in specific site's permission group or not,
Usually site have three groups Visitors, Members and Owners. If you have create another group and wants to check if particular user is present is that group for some validation so you can refer below code sample,

* Assuming you have basic knowledge of SharePoint coding.



Code:
private bool UserPresentInGroup(string groupName)
        {
            bool isAdmin = false;
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                { // User may not have permission to see site group or Group members....
                    using (SPSite oSite = new SPSite(strWebUrl))
                    {
                        using (SPWeb oWeb = oSite.OpenWeb())
                        {
                            SPGroup oUserGroup = oWeb.Groups[groupName];
                            foreach (SPUser item in oUserGroup.Users)
                            {
                                if (item.LoginName == currentUser.LoginName)
                                {
                                    isAdmin = true;
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception exp)
            {}// Catch exception

If you wants to check user from Sites default Visitor, Member or Owner Group you can directly get group by below property
  • SPWeb.AssociatedVisitorGroup
  • SPWeb.AssociatedMemberGroup
  • SPWeb.AssociatedOwnerGroup
instead of  oUserGroup.


--
Thanks,
Praveen Pandit

November 20, 2013

SharePoint Site lock, unlock, Web unable to update, delete, add options are invisible, unable to see recycle bin, site is locked, how to make site ready only , unlock site



SharePoint came with so many new features and functionality. it is stable and matured technology.
if user if unable to see edit, delete or Add button even has full control and contribute permission or also unable to see recycle bin. One of the reason of it you Site / Web is locked and no database related update can be made (in short no update). here you may got my point. the site or Content DB is locked we need to unlock it. it happens it your backup or restore is interrupted or some SharePoint job is couldn't completed.

Or some time you are doing some important task, like doing scheduled backup or restore. or anything related to it. so you don't want changes during you process. it simple lock it.

Now how should we lock ant site or unlock. the best and easiest way is PowerShell.


 PS C:\Users\Admin> $site =Get-SPSite -Identity “http://SiteOrWebUrl”  
 PS C:\Users\Admin> $site.MaintenanceMode   
 True  
 PS C:\Users\Admin> $Site.ClearMaintenanceMode  
 PS C:\Users\Admin> Set-SPSite -Identity “http://SiteOrWebUrl” -LockState "Unlock"  


Another way it stsadm command, which is also preferred and easy way.

 C:\Users\Admin> stsadm -o setsitelock -url http://xxx -lock none  


Don't forget to run command prompt with elevated privileges!


Please share yours findings or issue if any on this.

--
Thanks for visiting!!,
Praveen Pandit