Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to check of a folder exists? #241

Closed
RigidCollision opened this issue Jun 7, 2021 · 1 comment
Closed

Is there any way to check of a folder exists? #241

RigidCollision opened this issue Jun 7, 2021 · 1 comment
Labels

Comments

@RigidCollision
Copy link

Hi,
Having great fun with this API.
Is there a way of checking for existance of a folder in a parent please?

Tried getExists but no joy!

@vgrem vgrem added the question label Jun 9, 2021
@vgrem
Copy link
Owner

vgrem commented Jun 9, 2021

Hi there!

To determine whether folder exists the following approach could be considered:

$nonExistentFolderUrl = "/sites/team/archive";
$folder = $ctx->getWeb()->getFolderByServerRelativeUrl($nonExistentFolderUrl)->select(["Exists"])->get()->executeQuery();
if(!$folder->getExists()){
    print_r("Folder {$nonExistentFolderUrl} has not been found");
} 

Note: explicitly specifying Exists property via select method does the trick here, this way SharePoint API will not complain with System.IO.FileNotFoundException exception.

Same rule applies to File resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants