serving the solutions day and night

Pages

Wednesday, December 29, 2010

Check SharePoint user & their permissions

Below is the some methods to check user and their permissions levels are

SPSite.CheckPermissions
SPSite.DoesUserHavePermissions

SPWeb.CheckPermissions
SPWeb.DoesUserHavePermissions

SPList.CheckPermissions
SPList.DoesUserHavePermissions

SPListItem.CheckPermissions
SPListItem.DoesUserHavePermissions

.NET Code
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" %>

<%@ Import Namespace="Microsoft.SharePoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script runat="server">
  public void Page_load(object sender, EventArgs e)
  {
    SPWeb myWeb = SPContext.Current.Site.OpenWeb();
    if (myWeb.DoesUserHavePermissions("dns-server\\dnsuser", SPBasePermissions.EditListItems))
      lblMessage.Text ="dns-server\\dnsuser can edit list items";
    else
      lblMessage.Text = "dns-server\\dnsuser cannot edit list items";
  }
</script>
</asp:Content>

References:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.getusereffectivepermissions.aspx

No comments: