Get ItemID of files which have no checked in version

Had the requirement to get the CheckedOutFile collection of a SharePoint List programmatically and it had to include the ItemID for the file (for use in further programmation).

Via PowerShell you can quite easily get the Path Identity information which contains the ItemID:

PowerShell CheckedOutFiles

Notice that the number at the end is the ItemID.

However, via C# CSOM this is a lot harder as the ObjectPathIdentity class is “inaccessible due to its protection level”. You can’t directly get to this info so I created an extension method “GetPath” to get this info:

public static class ClientObjectExtensions
    public static string GetPath(this ClientObject o)
        string result = null;

        if (o != null)
            var q = o.GetType().InvokeMember("Path", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, o, null);
            var r = q.GetType().InvokeMember("Identity", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, q, null);

            result = r.ToString();

        return result;

Which can be integrated into the C# CSOM logic



Now you can extract this value from the string and continue to work with it as needed.


Links to this post


CAPTCHA Image Validation