I have a versioned item and its info object and I need to see whether it's checked out or not, however, when I view its info.LockType.Value, I see it has assigned "CheckedOut|Permanent". How can I compare against it? I've tried comparing against LockType.CheckedOut or LockType.Permanent and each returns false.

FullVersionInfo info = (FullVersionInfo)versionedItem.VersionInfo;

if (info.LockType.Value == LockType.CheckedOut)
{
     // I am not getting here when item is "CheckedOut|Permanent"}
  • I wonder if this is the 'explicit checkout' instead of the 'implicit checkout' when we open a Component? Maybe the API devs didn't have 2 properties to set, so they combined these 2 values in 1 property? – robrtc Jun 14 '13 at 3:44

In the backend it's a .NET enum with the "Flags" attribute specified so it's value can be a combination of the enum values.

Try this:

info.LockType.Value.HasFlag(LockType.CheckedOut)

Notice HasFlags was introduced in .NET 4.0, in older versions of .NET you have to use bit operations to check a specific bit.

Something like this:

(info.LockType.Value & LockType.CheckedOut) != 0
  • .HasFlag arrived with 3.5 – Dominic Cronin Jun 14 '13 at 6:53
  • Strange. I checked on MSDN, and there I can only choose .NET 4, .NET 4.5, and Silverlight. Oh well, a bit of bit manipulation has never harmed anyone. :) – Lars Møllebjerg Jun 14 '13 at 7:44
  • Sorry - you are right. My mistake. – Dominic Cronin Jun 14 '13 at 8:54

As of SDL Tridion 2013 you do not need to use FullVersionInfo. Now each of the RepositoryLocalObject items has LockInfo. So you can use component.LockInfo.LockType, for example.

Many thanks for all the answers! As it turns out, the following code also accomplishes what I am looking for, as it will detect all possible locks an item can acquire.

if (LockType.None != info.LockType)
 { ...  }

As Andrey mentions, this can now be done using the LockInfo property on the item.

I've just successfully implemented this using the following code:

RepositoryLocalObjectData item = Client.Read(itemId, new ReadOptions { LoadFlags = LoadFlags.Expanded}) as RepositoryLocalObjectData;

//It the item is locked for any reason (Checked-out, in Workflow, etc.) then don't try to process it
if (item.LockInfo.LockType.Value != LockType.None)
{
    //Do something here.
}

Hope this helps.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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