0

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.

1 Answer 1

0

There are probably files with no checked-in version. Can you navigate to the target library

library -> Library Settings -> Manage files which have no checked-in version

Please check if that page shows any files. If yes, then you can take ownership of those files and delete them from UI. The same can be accomplished via object model/powershell. If you are using powershell this link may help.

2
  • Perfect! It worked. Now, I can see those checkedout files in "Manage files which have no checked-in version". However, when I iterate via Powershell to this DocumentSet, I am not seeing this file. Is there any way in Powershell to delete it from "Manage files which have no checked-in version". Nov 14, 2016 at 8:12
  • You can use SPDocumentLibrary.CheckedOutFiles (see msdn.microsoft.com/en-us/library/office/…). It does not return you files per document set, but you can compare file path against document set URL to check if file is within the provided document set or folder.
    – sssreddy
    Nov 14, 2016 at 8:25

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.