Share via

Sharepoint CSOM GetChanges API : How to detect item checked out/in?

Nagarjuna B 6 Reputation points
2022-05-16T18:49:32.887+00:00

Hi,

We have a requirement where we need to programmatically detect whenever any items in a list have been checked out/in. I am currently using Sharepoint CSOM List.GetChanges API. It returns a ChangeItem object with the ChangeType property set to "Update" but it looks like no data is being returned that tells us what exactly has been updated(I couldn't find any property suggesting what properties have been changed).

  1. Am I missing something or is there no way to detect item checkedout/in ?
  2. The ChangeItem.Editor property(I assume this is what tells us who made the change) is not being populated, how do I get it populated? (interestingly, the editor property is being populated for ListItem.GetChanges!)

Remote event receivers solve the problem, it provides subscribing for specific events like ItemCheckingOut/In etc..but unfortunately we can't use remote event receivers.

Thank you.

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,261 Reputation points
    2022-05-17T07:20:51.99+00:00

    Hi @Nagarjuna B ,

    To help you better ,can you share any code on this issue to help me reproduce the problem?

    Based on my research and testing ,as a workaround, you can follow these code to get items have been checked out using CSOM :

            static void Main(string[] args)  
            {  
                var ctx = GetonlineContext();  
                Web oweb = ctx.Web;  
                ctx.Load(ctx.Web, a => a.Lists);  
                ctx.ExecuteQuery();  
      
                var listName = "test";  
                List list = ctx.Web.Lists.GetByTitle(listName);  
                var items = list.GetItems(  
                    new CamlQuery()  
                    {  
                        ViewXml = @"<View Scope='RecursiveAll'><Query>   
                <Where><IsNotNull><FieldRef Name='File_x0020_Type' /></IsNotNull></Where>   
                </Query></View>"  
                    });  
                ctx.Load(items, a => a.IncludeWithDefaultProperties(item => item.File, item => item.File.CheckedOutByUser));  
                ctx.ExecuteQuery();  
                foreach (var item in items)  
                {  
                    if (item.File.CheckOutType != CheckOutType.None)  
                    {  
                        Debug.WriteLine("File: " + item["FileRef"].ToString().Split('/').LastOrDefault());  
                        Debug.WriteLine("Checked-Out By: " + item.File.CheckedOutByUser.Title);  
                        Debug.WriteLine("Checked-Out User Email: " + item.File.CheckedOutByUser.Email);  
                        Debug.WriteLine("Last Modified: " + DateTime.Parse(item["Last_x0020_Modified"].ToString()));  
                        Debug.WriteLine("-----------------------");  
                        Debug.WriteLine("");  
                    }  
                }  
            }  
    

    My test result:

    202566-image.png
    Hope it can help you.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.


    Was this answer helpful?

    1 person found this answer helpful.

Your answer

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