I am trying to delete all content from site (list/folder/documentset). However, I am getting error while deleting couple of document sets.
#docsetFolder is an object of Document set which is correct.
for($x=$docsetFolder.Files.Count-1;$x -ge 0; $x--)
{
$listItem = $docsetFolder.Files[$x].Item;
$file = $listItem.File;
if($file -ne $Null)
{
$name = $file.CheckedOutByUser;
if($name -ne $Null) #IF checkout by some one then Undo Checkout.
{ $file.UndoCheckOut();
}
$file.Delete();
}
}
}
$docsetFolder.Delete(); #This line gives error
ErrorException calling "Delete" with "0" argument(s): "The file "/bu/abc/private/Shared Documents/xxx.docx" is checked out for editing by ."
Though, all file inside documentset got deleted, but while deleting document set I am getting error and document set not getting delete. Few DocumentSets are getting deleted in the same library.