Forum Discussion
CSOM challenge - SharePoint Online
Do you know a way to access file objects that you can see in UI under Library Settings -> "Manage files that have no checked in version" in a SharePoint Online doc. lib via PowerShell ?
I spent couple hours and can't seem to access them via CSOM. I have couple files that I need to check-in like that but I am failing to accomplish.
8 Replies
Hi,
Check the below script. To check files for "Manage files that have no checked in version", you need to use the condition :
$file.MajorVersion -eq "1" -and $file.Level -eq "Checkout"
This script uses SPO PnP also.
$cred=Get-Credential $UName=$cred.UserName.ToString() $Pass =$cred.GetNetworkCredential().Password $SiteURL = "https:// tenantname.sharepoint.com/sites/testsite2" $DocLibName = "Documents" connect-pnponline -Url $SiteURL -Credentials $cred $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") $Password = $Pass | ConvertTo-SecureString -AsPlainText -Force #Bind to site collection $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UName,$Password) $Context.Credentials = $Creds #Retrieve list $List = $Context.Web.Lists.GetByTitle($DocLibName) $Context.Load($List) $Context.ExecuteQuery() $Allfiles= $List.RootFolder.Files $Context.Load($Allfiles) $Context.ExecuteQuery() foreach( $file in $Allfiles){ If($file.MajorVersion -eq "1" -and $file.Level -eq "Checkout") { Set-PnPFileCheckedIn -Url $file.ServerRelativeUrl Write-Host $file.Name "Checked-in " } }- Ali SalihIron Contributor
NarasimaPerumal Chandramohan Thanks for the attempt, however it doesn't work. It doesn't show ANY files although I can see files in the UI. These files are uploaded by someone else besides me, but never fully checked-in in the first place. There is no 'version'. So $file.MajorVersion -eq "1" -and $file.Level -eq "Checkout" isn't a valid condition. Please see screenshots below.
1) Need to find where these files are located, and be able to load them up into the context
2) I need to take over the ownership with a similar method to on-premises SPCheckedOutFile.TakeOverCheckOut method. But that method doesn't exists because SPCheckedOutFile class doesn't exist in CSOM as far as I can see
Testing the script
.ItemCount shows 4 files
What I can see in UI
Hi,
Please download the below codeplex project[SharePoint Online Client Browser] and check the properties of the files that you are refering and then you change the script accordingly.