1

I'm writing a CSOM PS script to create folders in a doclib, and set permissions on them.

Anything works fine except when the folder name contains a %

I am able to create the folder using ResourcePath, FolderCollectionAddParameters and AddUsingPath following this article

But I can't get access to the folder using GetFolderByServerRelativeURL method.

The code is the following :

$folderurl="/sites/MySite/MydocLib/MyFolder %1"
$rpFolder = [Microsoft.SharePoint.Client.ResourcePath]::FromDecodedUrl($folderurl)
$CurrentFolder = $ctx.web.GetFolderByServerRelativeUrl($rpFolder)
$Ctx.Load($CurrentFolder)
$Ctx.ExecuteQuery()

And I get a "file not found" error.

Any help will be appreciated

1

I found the error : the GetFolderByServerRelativePath method must be used instead of GetFolderByServerRelativeUrl The right code is :

$folderurl="/sites/MySite/MydocLib/MyFolder %1"
$rpFolder = [Microsoft.SharePoint.Client.ResourcePath]::FromDecodedUrl($folderurl)
$CurrentFolder = $ctx.web.GetFolderByServerRelativePath($rpFolder)
$Ctx.Load($CurrentFolder)
$Ctx.ExecuteQuery()

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.