1

Will this work or break if fileUrl is blank or does not even exists?

SPFile file = web. GetFile (fileUrl); 

if (file == null)
{
    file.delete()
}

1 Answer 1

6

Use the exists property instead of null, GetFile method doesn't return null if file doesn't exist

SPFile file = web.GetFile(fileurl);

if(file.Exists) 
{
    //code here
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.