It's all about the answers!

Ask a question

How to programatically get the lock status of a file from a stream?

pugazhenthi samidurai (26423942) | asked Feb 21 '13, 3:59 a.m.
edited Oct 05 '17, 11:15 p.m. by David Lafreniere (4.8k7)

Hi ,

I have prepared a change set with some files and associated that change set to some work item. I have developed a Plugin which will take input of Work Item number and fetch the files inside change set(s) associated to it.

Now to enhance that plugin, I want to display the List of files from change set which are locked by any Team user.
Currently I am using the IsImmutable method of IFileItem class. But there are some refresh problems occurring like even after the user has released / Locked the file, same is not reflecting to my plugin ONLINE.
Is there any direct method to know whether the given file in the Stream was locked by an user or not.


Accepted answer

permanent link
John Riendeau (46626) | answered Feb 21 '13, 9:11 a.m.
SCMPlatform#getWorkspaceManager() will get you an IWorkspaceManager.  IWorkspaceManager#findLocks() should let you search for locks in a stream.  It takes an ILockSearchCriteria that you can customize to return exactly the locks you want.  (Use ILockSearchCriteria.LockSearchCriteriaFactory#newInstance() to create the ILockSearchCriteria.)
David Lafreniere selected this answer as the correct answer

pugazhenthi samidurai commented Feb 22 '13, 1:53 a.m. | edited Feb 22 '13, 1:56 a.m.

Hi John.
Thanks a lot. Based on your input i have followed the below link.

But it always shown as file locked.

My Code :

criteria = ILockSearchCriteria.FACTORY.newInstance();             

Note : i am using change set to get componet ,file handle and workspace handle is Stream. i need get the current status of a file(file is referred from change set) from Stream.


John Riendeau commented Feb 22 '13, 9:19 a.m.

I don't see anything obviously wrong with the way you're constructing your search criteria.  Maybe there's an issue with the code that's interpreting the results you're getting back?  Or (and sorry in advance for the stupid question) is it at all possible that the file actually is locked?  If you go to your project area in the web UI and choose Source Control --> Locks, do any locks appear?

David Lafreniere commented Oct 05 '17, 11:15 p.m.

John has the correct answer here. Please raise a defect if something is not working as expected.

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.