When was the file checked out on SharePoint Online?

Kamalpreet Singh 81 Reputation points
2021-03-18T18:59:18.743+00:00

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();
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,828 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,044 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,326 Reputation points
    2021-03-18T20:13:43.843+00:00

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


  2. Jerryzy 10,571 Reputation points
    2021-03-19T02:45:52.063+00:00

    Hi @Kamalpreet Singh ,

    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.


  3. Jerryzy 10,571 Reputation points
    2021-03-20T08:54:04.63+00:00

    Hi @Kamalpreet Singh ,

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.