Search This Blog

Tuesday, March 29, 2016

How to find current user has edit permissions in sharepoint 2013 programmatically?

//Get the current loged in user
 SPUser currentUser = SPContext.Current.Web.CurrentUser;

 using (SPSite site = new SPSite("http:\\servername\TestSite"))
 {
    site.AllowUnsafeUpdates = true;
    using (SPWeb web = site.OpenWeb())
    {
        SPList oList = web.Lists["Test"];
        if(oList!=null)
        {
           SPListItemCollection collListItems=lstAPAs.GetItems();
           if(collListItems!=null)
           {
               foreach (SPListItem oListItem in collListItems)
               {
                    bool Ispermission = Convert.ToBoolean(oListItem.DoesUserHavePermissions                                (currentUser, SPBasePermissions.EditListItems));
                   if(Ispermission)
                   {
                       //Current user has edit permission for the list item
                   }
                   else
                   {
                      //Current User doen't have permission for the list item
                   }
               }
          }
         }
         site.AllowUnsafeUpdates = false;
    }
  }

No comments:

Post a Comment