
Hi,
you can only check "CheckOutType" property. SharePoint Online don't save checkout date.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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();
Hi,
you can only check "CheckOutType" property. SharePoint Online don't save checkout date.
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.
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.