2

Is there a way to check if a file is checked out by another user? I am going trhough a list file by file and would like to avoid the "file is opened by another user" error. Something like this would be nice:

Guid id = new Guid(slideLibrary); // ID of Slide-Library.
List list = ctx.Web.Lists.GetById(id);
ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(items); // Loading all the fields
System.Security.SecureString pwd = new System.Security.SecureString();
foreach (char c in "pwd".ToCharArray()) pwd.AppendChar(c);

ctx.Credentials = new SharePointOnlineCredentials(login, pwd);
ctx.ExecuteQuery();

// Iterating through all the entries.
foreach (var item in items)
{
    String currentID = item["ID"].ToString(); // Getting the ID of the current item.

    if (!item.IsCheckedOut()) // This is the part I am looking for.
    {
       // Do stuff
    }
    else
    {
       Console.WriteLine("Item is blocked, skipping it.")
    }
}

I have yet not been able to find something fitting.

4

You can not get it from ListItem but you can get it from ListItem.File. For example

if(item.File.CheckOutType == CheckOutType.None){
// Do stuff...
} 

To use this code, you need to load the File along with the item. I mean

ctx.Load(items, item=> item.Include(f => f.File));
  • Loading the file in the way you described doesn't work for me. I get a compiler error on ìtem.File` that this does not exist for ListItemCollections. Am I doing something wrong? – UsefulUserName Aug 23 '16 at 5:47
  • You are right! Check my update – Atish Dipongkor - MVP Aug 23 '16 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.