What is the difference? (Checked out files)
-
10-12-2019 - |
Question
I am in the process of writing a powershell script to work with checked out files and I stumpled on this article: Find All Checked Out Files
My question is what is the difference between the two sections...
foreach ($item in $list.CheckedOutFiles) {...
and
foreach ($item in $list.Items) {
if ($item.File.CheckOutStatus -ne "None") {...
At first glance it looks like $list.CheckedOutFiles
returns a collection of SPCheckedOutFile
where as the second returns SPListItems
...
In what scenario would something be a part of $list.CheckedOutFiles
and not be part of the second?
My reason for asking is that I would rather only use the SPListItems because they have the properties available to me that I am looking for, but I want to make sure I am not missing something I need....
Solution
The script comes from this site initially:
It seems that the second loop is made to catch files that are missing in the collection of "CheckedOutFiles". It can be that there are files that never had a check in, meaning the "CheckOutStatus" not equals (-ne) "None". This can happen if you upload files programatically or if files have been uploaded before the requirement of checking in and checking out has been enabled.
See the original text: "One cool thing to point out about this is that it will also show you files that you normally can’t see – that is files that have been created by other users but have never had a check in. This is actually pretty cool and I stumbled upon this when trying to fine tune my Publish-SPListItems cmdlet. You see, if the file has never been checked in then iterating through the SPListItemCollection object will not reveal the item (or file I should say); this meant that my cmdlet, as it was previously written, was missing a bunch of files."