question

KamalpreetSingh-1405 avatar image
0 Votes"
KamalpreetSingh-1405 asked Jerryzy commented

When was the file checked out on SharePoint Online?

Is there a way to check when was a file checked out on SharePoint Online?
I'm trying to export a list of all checked-out files and also need their checked out date.

Using C#, I came up with following logic but cannot find any field that holds CheckedOutDate value.

 var DocLibName = "Documents";
    
 var list = ctx.Web.Lists.GetByTitle(DocLibName);
 ctx.Load(list);
 ctx.ExecuteQuery();
    
 string qCommand = "<View Scope=\"RecursiveAll\"><Query><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy></Query><RowLimit Paged=\"TRUE\">5000</RowLimit></View>";
    
 ListItemCollectionPosition position = null;
    
 List<ListItem> allItems = new List<ListItem>();
    
 do
 {
     var camlQuery = new CamlQuery();
     camlQuery.ListItemCollectionPosition = position;
     camlQuery.ViewXml = qCommand;
    
     ListItemCollection currentCollection = list.GetItems(camlQuery);
     ctx.Load(currentCollection);
     ctx.ExecuteQuery();
    
     position = currentCollection.ListItemCollectionPosition;
    
     allItems.AddRange(currentCollection);
    
     break;
 } while (position != null);
    
 var checkedoutUsers = allItems.Where(x => x.FieldValues["CheckoutUser"] != null).ToList();


office-sharepoint-onlinesharepoint-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KamalpreetSingh-1405 ,

Is there any update ? Did you try the modified code snippet in the latest post, it should be working for large list.

Thanks
Best Regards

0 Votes 0 ·
PeterFleischer-3316 avatar image
0 Votes"
PeterFleischer-3316 answered KamalpreetSingh-1405 edited

Hi,
you can only check "CheckOutType" property. SharePoint Online don't save checkout date.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for confirming.
Is there a way of checking how the file was checked out? My data export shows many checked out files have created date and modified date as same. As if file was checked out automatically when it was uploaded. Other users are getting frustrated because they cannot edit such file and no one sure how file being getting checked-out.

0 Votes 0 ·

Hi,
If you set "Check-out required" to "No" (in SettingsVersion of the library), you do not have this behaviour.

0 Votes 0 ·

I thought same but it is already set to No. And seems like it only happens with one user randomly. They upload files to SharePoint from a mapped drive by dragging and dropping from Email to mapped SharePoint drive.

0 Votes 0 ·
Jerryzy avatar image
0 Votes"
Jerryzy answered KamalpreetSingh-1405 commented

Hi @KamalpreetSingh-1405 ,

I modify based on your code as below to get the checked out files:

                 var DocLibName = "Documents";
                 var list = ctx.Web.Lists.GetByTitle(DocLibName);
                 ctx.Load(list);
                 ctx.ExecuteQuery();
    
                 string qCommand = "<View Scope=\"RecursiveAll\"><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy></Query><RowLimit Paged=\"TRUE\">5000</RowLimit></View>";
    
                 ListItemCollectionPosition position = null;
    
                 List<ListItem> allItems = new List<ListItem>();
    
                 do
                 {
                     var camlQuery = new CamlQuery();
                     camlQuery.ListItemCollectionPosition = position;
                     camlQuery.ViewXml = qCommand;
    
                     ListItemCollection currentCollection = list.GetItems(camlQuery);
                     ctx.Load(currentCollection, items => items.Include(item => item.File), items => items.ListItemCollectionPosition);
                     ctx.Load(currentCollection);
                     ctx.ExecuteQuery();
                     position = currentCollection.ListItemCollectionPosition;
                     allItems.AddRange(currentCollection);
                     break;
                 } while (position != null);
    
                 var checkedoutFile = allItems.Where(x => x.File.CheckOutType != CheckOutType.None).ToList();


Add "<Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq></Where>" in CAML so that return only files and ctx.Load(currentCollection, items => items.Include(item => item.File), items => items.ListItemCollectionPosition); is used to load item.file object to check the checkout type for the file.

Thanks
Best Regards


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I really appreciate the explanation you provided with answer. Thank you!

0 Votes 0 ·

My list is greater than 5000 items. Running updated code gives this error:

 The attempted operation is prohibited because it exceeds the list view threshold.

If I remove the Where condition in the query, then it gives following error:

 Object reference not set to an instance of an object on server. The object is associated with property File.



0 Votes 0 ·
Jerryzy avatar image
0 Votes"
Jerryzy answered

Hi @KamalpreetSingh-1405 ,

I keep the Caml Query same as original one and filter check out type for File Object only in Linq, please check the modified code to see if it works:

                 var DocLibName = "Documents";
                 var list = ctx.Web.Lists.GetByTitle(DocLibName);
                 ctx.Load(list);
                 ctx.ExecuteQuery();
    
                 string qCommand = "<View Scope=\"RecursiveAll\"><Query><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy></Query><RowLimit Paged=\"TRUE\">5000</RowLimit></View>";
    
                 ListItemCollectionPosition position = null;
    
                 List<ListItem> allItems = new List<ListItem>();
    
                 do
                 {
                     var camlQuery = new CamlQuery();
                     camlQuery.ListItemCollectionPosition = position;
                     camlQuery.ViewXml = qCommand;
    
                     ListItemCollection currentCollection = list.GetItems(camlQuery);
                     ctx.Load(currentCollection, items => items.Include(item => item.File), items => items.ListItemCollectionPosition);
                     ctx.Load(currentCollection);
                     ctx.ExecuteQuery();
                     position = currentCollection.ListItemCollectionPosition;
                     allItems.AddRange(currentCollection);
                     break;
                 } while (position != null);
    
                 var checkedoutFilesList = allItems.Where(x => x.FileSystemObjectType == FileSystemObjectType.File && x.File.CheckOutType != CheckOutType.None).ToList();



If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.