TransWikia.com

App Installed Event Receiver -> Access Denied

SharePoint Asked by Garima on January 8, 2021

I am using AppInstalled event receiver to create a list in host web and then breaking its role inheritance. The list is created successfully but I am getting "Access Denied" while breaking role inheritance. The host web is MySite. The code is as follows:

using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false))
            {
                if (clientContext != null)
                {
                    Web hostWeb = clientContext.Web;
                    clientContext.Load(hostWeb);
                    clientContext.ExecuteQuery();

                    var listCollection = hostWeb.Lists;
                    _spService.CreateListInHostWeb(Constants.LIBRARY_NAME, Constants.TEMPLATEID_DOCUMENTLIBRARY, listCollection);
                    clientContext.Load(listCollection);
                    clientContext.ExecuteQuery();
                    //code to break role inheritance
                    List library = hostWeb.Lists.GetByTitle(Constants.LIBRARY_NAME);
                    submissionLibrary.BreakRoleInheritance(false, false);
                    clientContext.ExecuteQuery(); //error here
                }
            }

I have assigned the following permission

<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Manage" />
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="FullControl" >
  <Property Name="BaseTemplateId" Value="101" />
</AppPermissionRequest>

One Answer

I'm not 100% sure, but from what i see, i guess you should not use

_spService.CreateListInHostWe

but add library to

listCollection

using

ListCreationInformation

Answered by Evlo on January 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP