phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Check if file/folder exists, when entity name contains "#"?

Open F4T4LERROR opened this issue 1 year ago • 0 comments

Hello,

The developer, @vgrem has already provided comments on how to check if a folder exists in issue 241.

However, this doesn't appear to work if the SharePoint file/folder name contains a "#" symbol. I tried using rawurlencode on the folder name and path, but no joy. I can create/edit/delete files/folders that contains the "#" symbol. I can create entities inside of those folders in SharePoint using PHPSPO. But I can't check if they exist. Am I doing something wrong? Is this not possible?

$checkFolder = "/sites/company/jobs/Job-ABC123 #2";
$folder = $ctx->getWeb()->getFolderByServerRelativeUrl($checkFolder)->select(["Exists"])->get()->executeQuery();
if(!$folder->getExists()){
    print_r("Folder {$checkFolder} has not been found");
} else {
    print_r("Folder {$checkFolder} has been found");
}

Note, it also doesn't work if I use $checkFolder = rawurlencode("/sites/company/jobs/Job-ABC123 #2");

Or if I use: $folder = $ctx->getWeb()->getFolderByServerRelativeUrl(rawurlencode($checkFolder))->select(["Exists"])->get()->executeQuery();

Any guidance or clarification appreciated.

F4T4LERROR avatar Mar 21 '23 13:03 F4T4LERROR