Forum Discussion
Problem in Deleting Remote Event Receiver in Sharepoint
Hi ,
I have attached Remote event Receiver to a document library using Provider hosted app.Now i am trying to delete (Provider hosted app) the same remote event Receiver but i am getting "Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Access denied. You do not have permission to perform this action or access this resource." error.
Is there any other way apart from running powershell script to delete the attached remote event Receiver
- David OpdendriesCopper Contributor
You need to remove the remote event reciever using the same ClientID that created it. So if your provider hosted app with a specific clientid was used to create the event reciever you will get access denied if you try to delete it with powershell using your credentials. However i do believe that the pnp powershell Connect-SPOnline has some parameters to connect with clientid and secret. You should be able to delete it then
I do - Deleted
You can do this first by searching it in the SharePoint ClientBrowser and then use a powershell script to delete it.
function Get-SPOListEventreceivers { param ( [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, [Parameter(Mandatory=$true,Position=3)] [string]$Url, [Parameter(Mandatory=$true,Position=4)] [string]$ListTitle, [Parameter(Mandatory=$true,Position=5)] [GUID]$EventReceiverGUID ) $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) try { $ctx.ExecuteQuery() } catch [Net.WebException] { Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red } $ctx.Load($ctx.Site) $lista=$ctx.Web.Lists.GetByTitle($ListTitle) $ctx.Load($lista) $ctx.ExecuteQuery() $recevery=$lista.EventReceivers $ctx.Load($recevery) $ctx.ExecuteQuery() Write-Host "Found " $recevery.Count " receivers in " $lista.Title $recevery.GetById($EventReceiverGUID).DeleteObject() try { $ctx.ExecuteQuery() Write-Host "receiver removed" } catch [Net.WebException] { Write-Host "Failed to delete the receiver" $_.Exception.Message.ToString() -ForegroundColor Red } } # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" # Insert the credentials and the name of the admin site $Username="spadmin@xxx.onmicrosoft.com" $password = "$xxxx" $url = "https://xxxx.sharepoint.com/sites/S046WW16776" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $Url="https://xxx.sharepoint.com/sites/S046WW16776" $ListTitle="Project Metadata" $EventReceiverGUID="8ded46d9-6b87-4dac-9532-64d013122e92" Get-SPOListEventreceivers -Username $Username -AdminPassword $AdminPassword -Url $Url -ListTitle $ListTitle -EventReceiverGUID $EventreceiverGUID
- bhartisemwal1990Copper Contributor
yeah i think now powershell is the only option .
Because the issue was not with the appid change but the farm id change because of which the entire AppId was not matching and hence giving access denied error.
Thanks for replies :)
- Prerak DesaiCopper Contributor
Powershell method gives access denied error. Is there any way we can deleted the event receiver without deleting the list
- john johnSteel Contributor
Prerak DesaiI am facing the exact same issue.. unable to remove the RER using PnP either