0

I'm trying to get the list item permission using restapi in asp.net mvc. i had get the permission using below url

https://XXXXX.sharepoint.com/sites/AppDevelopment/PM/Data/_api/web/lists/getbytitle('Task')/items(45)/getusereffectivepermissions('LoginName')

Output

<?xml version="1.0" encoding="UTF-8"?>
-<d:GetUserEffectivePermissions m:type="SP.BasePermissions" xmlns:gml="http://www.opengis.net/gml" xmlns:georss="http://www.georss.org/georss" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"><d:High m:type="Edm.Int64">2147483647</d:High><d:Low m:type="Edm.Int64">4294967295</d:Low></d:GetUserEffectivePermissions>

Code i tried

    string requestUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items({2})/getusereffectivepermissions('{3}')", siteUrl, listName, id, HttpUtility.UrlEncode(userName));
    string result = RestApi_GetJsonTemp(accesstoken, requestUrl, "application/json; odata=verbose", "application/json; odata=verbose");
    BasePermissions permissionJson = new BasePermissions();
    using (TextReader sr = new StringReader(result))
    {
        JsonReader jsonreader = new JsonReader(sr, null);
        permissionJson.FromJson(jsonreader);

    }

how to use this high and low value to know what the permission?

4

The following example demonstrates how to:

Example:

function getListPermissions(webUrl,listTitle,accountName) 
{
    var endpointUrl = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getusereffectivepermissions(@u)?@u='" + encodeURIComponent(accountName) + "'";
    return $.getJSON(endpointUrl);
}

Usage

var accountName = 'i:0#.f|membership|jdoe@contoso.onmicrosoft.com'
var listTitle = 'Tasks';
getListPermissions(_spPageContextInfo.webAbsoluteUrl,listTitle,accountName)
.done(function(data)
{
    var permissions = new SP.BasePermissions();
    permissions.initPropertiesFromJson(data);
    if (permissions.has(SP.PermissionKind.viewListItems)){
       console.log(String.format('User can access {0} list',listTitle));    
    }
})
.fail(function(error){
    console.log(JSON.stringify(error));
});

C# version

Since getusereffectivepermissions method returns Microsoft.SharePoint.Client.BasePermissions object that consists of the following properties :

  • High - Specifies the most-significant 32 bits of the BasePermissions uint
  • Low - Specifies the least-significant 32 bits of the BasePermissions uint

the following classes have been introduced:

Having said that, below is provided the C# example that demonstrates how to determine user permissions:

using (var client = new SPHttpClient(webUri, userName, password))
{
     string endpointUrl = webUri + "/_api/web/lists/getbytitle('" + listTitle + "')/getusereffectivepermissions(@u)?@u='" + Uri.EscapeDataString(accountName) + "'";
     var data = client.GetJson(endpointUrl);
     var permissions = BasePermissions.ParseFromJson(data);
     if (permissions.Has(PermissionKind.ViewListItems)){
                Console.WriteLine("User {0} can access {1} list",accountName,listTitle);    
     }
 }

where SPHttpClient class is a Http client for SharePoint Online , follow Consume SharePoint Online REST service using .NET article for a details.

  • This is in jsom. i need in csom? – Aravind Sivam May 13 '15 at 11:16
  • This is not neither JSOM nor CSOM, this is REST API using JavaScript. I'm confused with your question, could you clarify your question? – Vadim Gremyachev May 13 '15 at 11:21
  • Your saying about SP.BasePermissions that is Client Side. I need in Server Side. – Aravind Sivam May 13 '15 at 11:23
  • Server Side or Client Side Object Model ? I'm still confused.. Can you explain why your question is tagged with REST but at the same time you are asking about Server Side? – Vadim Gremyachev May 13 '15 at 11:26
  • 2
    I would recommend you to get acquainted with Choose the right API set in SharePoint 2013 article to get familiar with APIs and then ask. I guess you need to consume SharePoint REST API in C#, isn't it? – Vadim Gremyachev May 13 '15 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.