How to verify check-out status for a file in a document library using CSOM
Assume the following method for retrieving a file
private static ListItem GetListItem(string url, ICredentials creds, string listTitle,int listItemId)
{
using (var clientContext = new ClientContext(url))
{
clientContext.Credentials = creds;
var list = clientContext.Web.Lists.GetByTitle(listTitle);
var listItem = list.GetItemById(listItemId);
clientContext.Load(list);
clientContext.Load(listItem,i => i.File);
clientContext.ExecuteQuery();
return listItem;
}
}
then to verify checkout state of a file (CheckOutType)
var listItem = GetListItem("https://contoso.sharepoint.com", credentials, "Documents", 1);
var file = listItem.File;
if (file.CheckOutType != CheckOutType.None)
{
//file was checked out
}
How to verify check-out status (SPFile.SPCheckOutStatus) for a file in a document library using SSOM
SPFile file = item.File;
if (file.CheckOutStatus != SPFile.SPCheckOutStatus.None)
{
//file was checked out
}