CSOM challenge - SharePoint Online

%3CLINGO-SUB%20id%3D%22lingo-sub-43697%22%20slang%3D%22en-US%22%3ECSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43697%22%20slang%3D%22en-US%22%3EHey%20community.%3CBR%20%2F%3E%3CBR%20%2F%3EDo%20you%20know%20a%20way%20to%20access%20file%20objects%20that%20you%20can%20see%20in%20UI%20under%20Library%20Settings%20-%26gt%3B%20%22Manage%20files%20that%20have%20no%20checked%20in%20version%22%20in%20a%20SharePoint%20Online%20doc.%20lib%20via%20PowerShell%20%3F%3CBR%20%2F%3E%3CBR%20%2F%3EI%20spent%20couple%20hours%20and%20can't%20seem%20to%20access%20them%20via%20CSOM.%20I%20have%20couple%20files%20that%20I%20need%20to%20check-in%20like%20that%20but%20I%20am%20failing%20to%20accomplish.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44087%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44087%22%20slang%3D%22en-US%22%3EAnyone%20else%20%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-43777%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43777%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3694%22%20target%3D%22_blank%22%3E%40NarasimaPerumal%20Chandramohan%3C%2FA%3E%26nbsp%3BI%20did.%20Here%20is%20the%20screenshot.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20128px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F10508iC5268248D9B3F425%2Fimage-size%2Fsmall%3Fv%3D1.0%26amp%3Bpx%3D200%22%20alt%3D%222017-02-03_7-37-17.png%22%20title%3D%222017-02-03_7-37-17.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EItems%20are%20not%20shown.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-43775%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43775%22%20slang%3D%22en-US%22%3E%3CP%3ECan%20you%20check%20%22Root%20Folder%22%20under%20%22Status%20Reports%22%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-43773%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43773%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3694%22%20target%3D%22_blank%22%3E%40NarasimaPerumal%20Chandramohan%3C%2FA%3E%26nbsp%3BI%20already%20used%20SharePoint%20Online%20Client%20Browser%2C%20and%20there%20are%20no%20files%20to%20be%20found.%20ItemCount%20shows%204%20there%20as%20well%2C%20but%20Item%20are%200.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20200px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F10507i162CB960EAE83BD4%2Fimage-size%2Fsmall%3Fv%3D1.0%26amp%3Bpx%3D200%22%20alt%3D%222017-02-03_7-23-28.png%22%20title%3D%222017-02-03_7-23-28.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3E4%20files%20do%20not%20show%20anywhere.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-43768%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43768%22%20slang%3D%22en-US%22%3E%3CP%3EI%20already%20used%20the%20SPCB.%20It%20doesn't%20see%20the%20files%20anywhere.%20ItemCount%20is%20reporting%204%20there%20as%20well.%20But%20no%20files%20in%20sight.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20style%3D%22width%3A%20276px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F10506iFE3BEAF2357B7839%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%222017-02-03_7-23-28.png%22%20title%3D%222017-02-03_7-23-28.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-43767%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43767%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20download%20the%20below%20codeplex%20project%5BSharePoint%20Online%20Client%20Browser%5D%20and%20check%20the%20properties%20of%20the%20files%20that%20you%20are%20refering%20and%20then%20you%20change%20the%20script%20accordingly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fspcb.codeplex.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fspcb.codeplex.com%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-43746%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43746%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3694%22%20target%3D%22_blank%22%3E%40NarasimaPerumal%20Chandramohan%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20attempt%2C%20however%20it%20doesn't%20work.%20It%20doesn't%20show%20ANY%20files%20although%20I%20can%20see%20files%20in%20the%20UI.%20These%20files%20are%20uploaded%20by%20someone%20else%20besides%20me%2C%20but%20never%20fully%20checked-in%20in%20the%20first%20place.%20There%20is%20no%20'version'.%26nbsp%3B%20So%20%3CEM%3E%3CU%3E%24file.MajorVersion%20-eq%20%221%22%20-and%20%24file.Level%20-eq%20%22Checkout%3C%2FU%3E%22%3C%2FEM%3E%20isn't%20a%20valid%20condition.%20Please%20see%20screenshots%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20Need%20to%20find%20where%20these%20files%20are%20located%2C%20and%20be%20able%20to%20load%20them%20up%20into%20the%20context%3C%2FP%3E%3CP%3E2)%20I%20need%20to%20take%20over%20the%20ownership%20with%20a%20similar%20method%20to%20on-premises%20%3CEM%3ESPCheckedOutFile.TakeOverCheckOut%3C%2FEM%3E%20method.%20But%20that%20method%20doesn't%20exists%20because%20%3CEM%3ESPCheckedOutFile%20%3C%2FEM%3Eclass%20doesn't%20exist%20in%20CSOM%20as%20far%20as%20I%20can%20see%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F10498i4194D95DCA26E429%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222017-02-03_5-55-56.png%22%20title%3D%222017-02-03_5-55-56.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ETesting%20the%20script%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20512px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F10500iA7AB86571CACA7BB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222017-02-03_6-23-40.png%22%20title%3D%222017-02-03_6-23-40.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3E.ItemCount%20shows%204%20files%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F10497i7E1A00183F6EE5EB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222017-02-03_5-57-46.png%22%20title%3D%222017-02-03_5-57-46.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EWhat%20I%20can%20see%20in%20UI%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-43714%22%20slang%3D%22en-US%22%3ERe%3A%20CSOM%20challenge%20-%20SharePoint%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-43714%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheck%20the%20below%20script.%20To%20check%20files%20for%26nbsp%3B%3CSPAN%3E%22Manage%20files%20that%20have%20no%20checked%20in%20version%22%2C%20you%20need%20to%20use%20the%20condition%20%3A%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24file.MajorVersion%20-eq%20%221%22%20-and%20%24file.Level%20-eq%20%22Checkout%22%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20script%20uses%20SPO%20PnP%20also.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24cred%3DGet-Credential%0A%24UName%3D%24cred.UserName.ToString()%0A%24Pass%20%3D%24cred.GetNetworkCredential().Password%0A%24SiteURL%20%3D%20%22https%3A%2F%2F%20tenantname.sharepoint.com%2Fsites%2Ftestsite2%22%0A%24DocLibName%20%3D%20%22Documents%22%0A%0Aconnect-pnponline%20-Url%20%24SiteURL%20-Credentials%20%24cred%0A%0A%24loadInfo1%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client%22)%0A%24loadInfo2%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client.Runtime%22)%0A%24Password%20%3D%20%24Pass%20%7C%20ConvertTo-SecureString%20-AsPlainText%20-Force%0A%0A%23Bind%20to%20site%20collection%0A%24Context%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SiteURL)%0A%24Creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24UName%2C%24Password)%0A%24Context.Credentials%20%3D%20%24Creds%0A%23Retrieve%20list%0A%24List%20%3D%20%24Context.Web.Lists.GetByTitle(%24DocLibName)%0A%24Context.Load(%24List)%0A%24Context.ExecuteQuery()%0A%0A%24Allfiles%3D%20%24List.RootFolder.Files%0A%24Context.Load(%24Allfiles)%0A%24Context.ExecuteQuery()%0Aforeach(%20%24file%20in%20%24Allfiles)%7B%0A%0AIf(%24file.MajorVersion%20-eq%20%221%22%20-and%20%24file.Level%20-eq%20%22Checkout%22)%0A%7B%0ASet-PnPFileCheckedIn%20-Url%20%24file.ServerRelativeUrl%0AWrite-Host%20%24file.Name%20%22Checked-in%20%22%0A%7D%0A%7D%20%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor
Hey community.

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
Highlighted

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 "
}
} 
Highlighted

@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 scriptTesting the script

.ItemCount shows 4 files.ItemCount shows 4 files

What I can see in UIWhat I can see in UI

Highlighted

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.

 

https://spcb.codeplex.com/

Highlighted

I already used the SPCB. It doesn't see the files anywhere. ItemCount is reporting 4 there as well. But no files in sight.

2017-02-03_7-23-28.png

 

 

Highlighted

@NarasimaPerumal Chandramohan I already used SharePoint Online Client Browser, and there are no files to be found. ItemCount shows 4 there as well, but Item are 0.

 

4 files do not show anywhere.4 files do not show anywhere.

Highlighted

Can you check "Root Folder" under "Status Reports"?

Highlighted

@NarasimaPerumal Chandramohan I did. Here is the screenshot.

Items are not shown.Items are not shown.

Highlighted
Anyone else ?