0

I am making a REST request to SharePoint for breaking the role inheritance for a folder.

It's working fine when a folder does not have any special character in it's name.

But when I add special charter(s) to a folder name, my request for breakroleinheritance is failing and I am getting below error from the web service.

"error":{"code":"-1, Microsoft.SharePoint.Client.ResourceNotFoundException","message":{"lang":"en-US","value":"Cannot find resource for the request SP.RequestContext.current/web/GetFolderByServerRelativeUrl('/foldertop/subfolder/2020/Oklahoma/20-4152 test permission for parts2020%23%40%26')/ListItemAllFields/."}}}

For example: 20-4152 test permission for parts2020#@& this is my folder name and after doing URL ending it becomes 20-4152%20test%20permission%20for%20parts2020%23%40%26.

Below is the full endpoint along with relative URL for my folder, Please know that if I remove the special characters #@& then same request is working fine.

https://mysharepoint.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/foldertop/subfolder/2020/Oklahoma/20-4152%20test%20permission%20for%20 parts2020%23%40%26')/ListItemAllFields/breakroleinheritance(true)

Does this mean that the SharePoint REST API request does not support special characters?

1

Microsoft has made some changes to support some of the old special characters that used to be restricted.

Supporting % and # in files and folders with the ResourcePath API

So instead of using GetFolderByServerRelativeUrl you need to use GetFolderByServerRelativePath.

This question/answer is about the same problem (the hash #): SharePoint Online folder with "#" not found

| improve this answer | |
  • I just tried bt removing slash before library name, and did encoding as you have mentioned which makes the endpoint like this. endpoint=>midwestmach.sharepoint.com/_api/web/… But I am still getting the same error – sagar Feb 10 at 9:04
  • here is the error : Cannot find resource for the request SP.RequestContext.current/web/GetFolderByServerRelativeUrl('topfolder/subfolder/2020/Oklahoma/20-4152 test permission for parts2020#@&')/ListItemAllFields/. – sagar Feb 10 at 9:05
  • Did you encode the rest of the folder path and use the variable instead in your code? – Christoffer Feb 10 at 9:08
  • Yes I did and it makes my url look like this => mysharepoint.sharepoint.com/_api/web/… – sagar Feb 10 at 9:10
  • My misstake, according to MS there should be a slash in the start. however i think you should write it as /breakroleinheritance(copyRoleAssignments=true, clearSubscopes=true) and not just (true). – Christoffer Feb 10 at 9:16

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.