csom,sharepoint-online , Determine which list a provider hosted application has access to


Determine which list a provider hosted application has access to

Question:

Tag: csom,sharepoint-online

I have created a simple Provider Hosted App ( straight out of the Visual Studio 2013 box )

The App has been granted "Read List Permissions" in the app manifest.

When the app is deployed SharePoint Online asks the User to select the list that the app can access. This should give it permission to read one specific list on the Host Web.

I cannot figure out how the MVC Provider Hosted Web part of the application actually determines which SharePoint list the end user has granted it permission to read.

Presumable it gets some sort of token to tell it which list it can read? Or is their a CSOM/JSOM call that will reveal which list it can access?


Answer:

To determine which list the user has granted permission to read you could consider the following approach:

Example

1)For current user

using (var ctx = new ClientContext(webUri))
{
        var web = ctx.Web;

        ctx.Load(web.Lists,
             lists => lists.Include(list => list.Title,
                                    list => list.EffectiveBasePermissions));

        ctx.ExecuteQuery();
        var currentUserLists = web.Lists.Where(l => l.EffectiveBasePermissions.Has(PermissionKind.OpenItems));
}

2)For any user

using (var ctx = new ClientContext(webUri))
{
     var web = ctx.Web;

     //load lists
     ctx.Load(web.Lists);
     ctx.ExecuteQuery();
     //load lists permissions for a specified user
     var listsPermissionsResults = web.Lists.ToDictionary(list => list, list => list.GetUserEffectivePermissions(loginName));
     ctx.ExecuteQuery();

     //filter lists where user has been granted permissions to open list 
     var userLists = new List<List>();
     foreach (var result in listsPermissionsResults)
     {
           var list = result.Key;
           var listPermissions = result.Value.Value;
           if (listPermissions.Has(PermissionKind.OpenItems))
           {
                userLists.Add(list);
            }
     }
}

Related:


jQuery .css() not getting background position w/o !important in css


jquery,css,dom,csom
I am hoping someone could help me understand why the jQuery .css() (v1.11) method is returning 0% 0% for elements that have a non-overridden background position defined (in the inspector while running and in the style sheet). What I found a bit puzzling is why when I force an !important...

Checking if current user can view list in SharePoint CSOM


sharepoint,csom
How do I determine if the current user can view list items or read a list in SharePoint Online / Office365? I have some working code that returns the lists // Retrieve all lists from the server. context.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.Id, list => list.Hidden, list...

Add Button in SharePoint List Ribbon Button Using JSOM


javascript,sharepoint,ecmascript-5,csom
I have to add a button in Sharepoint List Ribbon button & in ECB Menu. here is the code to add ECB menu in Sharepoint List using JSOM. function AddCustomActions() { var listTitle = 'mylist Title'; var clientContext = new SP.ClientContext(); var oWebsite = clientContext.get_web(); var oList = oWebsite.get_lists().getByTitle(listTitle); var...

How to redirect a URL in SharePoint Online?


sharepoint,sharepoint-online
I have a site setup in SharePoint online at: aaa.sharepoint.com/fr The trouble is that this is an internal acronym and new staff always go to the long version of this URL. Is there a way I can redirect aaa.sharepoint.com/fundraising to aaa.sharepoint.com/fr without having to create another SharePoint site and a...

How to prevent fill in values when saving over CSOM to a choice field


c#,sharepoint,csom
I am writing some ETL code to move data between an external system and SharePoint Online. I am using the nuget package Microsoft.SharePointOnline.CSOM to communicate with SP in C#. I am using the following code to update my field values. spListItem[fieldName] = "Test Value"; spListItem.Update(); spClientContext.ExecuteQuery(); I noticed with Choice...

SharePoint Online (Office 365) login form in a Office task pane app


office365,sharepoint-online,apps-for-office
The end goal of what I am trying to achieve is to open a page from a SharePoint Online instance - any page, it doesn't matter - in a Office Task Pane app. The issue is that the login page (https://login.microsoftonline.com) is shown fine, but when you click 'login' it...

C# CSOM - Check if File Exists in Document Library


c#,sharepoint,office365,csom
I'm coding in C# using CSOM, my app uploads a template asp.net page to the "/Pages/" library, I need it to check if a file exists in that location with the same name prior to file upload (then maybe it can return a bool value). I did have a quick...

SharePoint Online integrated with CRM Online says, “We're sorry, we can't sync because you've run out of space.”


dynamics-crm,sharepoint-online
I was trying to sync my document on SharePoint Online where I got an error saying, "we're sorry, we can't sync because you've run out of space." I believe this is independent of the CRM storage space we get (which is still under 8% filled for my CRM organization) How...

Creating term fails in SP 2013


c#,sharepoint,sharepoint-2013,csom
I am trying to create a term in a SP 2013 term set. I am able to read the terms from the term set with the given credentials. Settings: The ServiceAccountLogonName user is one of the Term Store Admins Code: var siteUrl = ConfigHelper.GetValue("SharepointSiteUrl"); var clientContext = new ClientContext(siteUrl); clientContext.Credentials...

How to enableMajor?


list,sharepoint,csom
How could I enable Major versioning on "Pages" list? My code is not working and I don't get any errors. Any suggestions?.... _spBodyOnLoadFunctionNames.push(onPageLoad()); function onPageLoad() { ExecuteOrDelayUntilScriptLoaded(enableMajor, 'SP.js') } function enableMajor() { var ctx = new SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle('Pages'); ctx.load(list); ctx.executeQueryAsync( function () { list.enableMajor = true; },...

SHAREPOINT 2013: How can I read Site column contents and modify them via javascript csom?


javascript,sharepoint-2013,csom
I'm relative new to Sharepoint 2013, I'm trying to access and display on a page the contents inside a specific "Site Column", I've have been reading a lot about this, but I still can't accomplish my task. So far I get to this: 'use strict'; var hostweburl; var appweburl; $(function...

Retrieve all instances of recurring event via CSOM


c#,rest,sharepoint-2013,sharepoint-api,sharepoint-online
I need to get all the instances of a recurring calendar event in Sharepoint 2013 online via CSOM. I read that it can't be done, that I need to do it via REST API directly. My question: 1) Is it possible to get the items from a View instead of...

SHAREPOINT 2013: How can I update a Site Column with the content of an array with javascript CSOM?


javascript,sharepoint-2013,csom,site-column
I'm relative new to Sharepoint 2013, I'm trying to update the content of a Site column with the content of an array, I can retrieve and visualize the content of my site column, the user is able to change and save the necessary part and the changes are saved into...

Call Javascript After Saving Calendar Item


javascript,sharepoint,csom
I am having a script as below:- function getColorValue(aId,atitle) { try{ var clientContext = new SP.ClientContext(); var oWebsite = clientContext.get_web(); var oList = oWebsite.get_lists().getByTitle('Item type'); var oListItem = oList.getItemById(parseInt(aId)); clientContext.load(oListItem); clientContext.executeQueryAsync(function () { var listItem = oListItem; var colorname = listItem.get_item('Color_x0020_Name'); if (typeof colorname != 'undefined') { if (colorname !=...

Thumbnails in Sharepoint online


sharepoint-online
I need to show thumbnails of Sharepoint Online images on my website, to avoid downloading all images beforehand. Is it possible to make Sharepoint Online (Office365) automatically create thumbnails (user defined size) of images that you upload? Or is it possible to make SO scale the image before download, by...