How to display a short term lock in a view?
Hello,

I discovered recently the two checkin/checkout modes in sharepoint.
The long term ckeckout that the user choose explicitly to have and the short term check out when the user open an office document for modification.

This article describe the differences between the two modes: http://blogs.technet.com/harikumh/archive/2008/05/28/check-out-feature-of-sharepoint-2007.aspx

The short term checkout is perfect for my client needs. He doesn't want to checkout a document every time he opens it + a lot of user doesn't understand why to check-in a document when they have done their works.

Here is my problem: I would like to display the short term lock in my document library the same way the long term lock information is displayed.
By code I'm able to see who has acquired the lock and if it is a short term or long term lock:

SPFile.SPCheckOutStatus
The column "CheckedOutBy" in by document library does not display anything for the short term lock. The document icon is not change to display a lock on it.

So I'm searching for an idea, how to be able to display this information in my view?

Best Regards,
Py

November 21st, 2009 9:10am

Hi,

Solutions

1 .This is the linkfor SPFile object in which you will find

http://msdn.microsoft.com/en-us/library/dd587246(office.11).aspx

In this there is the member in SPFile which is

CheckedOutDate -->System.DateTime -->Gets the date and time that the file was checked out.

This can be used to find check out time

2. Create the Column Check out time in List.
Handle SPItemEventReceiver for that List item

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver_members.aspx

when that document check out event fire update the listitem with Checkout time.
With this you can create the view depend onCheck out time in which you can find long term lock.

Free Windows Admin Tool Kit Click here and download it now
November 21st, 2009 1:36pm

Hi Shrivallabh,

Sounds good, but are you sure that ItemCheckedOut is triggered by short-term lockout? I have serious doubts...

Should be checked.

Peter
November 21st, 2009 7:06pm

Thanks a lot for the idea. I will check tomorrow if this solution is working.
I hope the event is triggered. (please please)

Best regards,
Py
Free Windows Admin Tool Kit Click here and download it now
November 22nd, 2009 9:27pm

The hope is the last to die! :-)

Peter
November 23rd, 2009 2:28am

And the hope has just died :-(
No event is triggered for a short term lock.

This solution is not possible...

I wonder why this information is not displayed in the list and not present in the metadata?

Py
Free Windows Admin Tool Kit Click here and download it now
November 23rd, 2009 9:12am

Hello,

A short term lock is an implicit checkout. It is put by an external application like MSOffice when a document is modified.

"We have 2 kinds of Check outs, Short term and long term. If you click the drop-down of a document in aDoc lib and choose check out, that is a long term. When Word opens the document in Read-Write mode, it places a short term checkout on the document."


I've also discovered that this lock can be access by the SPFile.properties["vti_sourcecontrollockexpires"] metadata. The problem is this metadata can't be access from a view.

Py
November 23rd, 2009 10:07am

Hi,

Go through this which might helpfull to you put event handler,

http://msdn.microsoft.com/en-us/library/cc664707.aspx
Free Windows Admin Tool Kit Click here and download it now
November 23rd, 2009 11:06am

Thank you for your help Shrivallabh.

I've also read this article. As you can see, they use the ItemCheckoutEvent to prevent user to make some "long term check out" and use ItemUpdatingEvent to prevent user to save modification after a "short term check out". No solution is given to catch a short term check out.

Py
November 23rd, 2009 12:09pm

Hi,

Theoretically you can do the following:
Create a custom web service based on the object model to get the value of vti_sourcecontrollockexpires metadata of a file remotely.

Create a custom field that display the information in edit and display view based on the of vti_sourcecontrollockexpires metadata using the object model in a label. Create a RenderPattern for the list view that contains a JavaScript block that calls your custom web service to display the short lock information.

I suggest you to read these basic articles that describe the process of custom field type creation:
Create custom field types for SharePoint
http://www.sharepointblogs.com/nicksevens/archive/2007/08/31/create-custom-field-types-for-sharepoint.aspx
Developing Custom Field Types for SharePoint 2007
http://msdn.microsoft.com/en-us/magazine/dd727508.aspx
Building Custom Field Types in Windows SharePoint Services 3.0
http://msdn.microsoft.com/en-us/library/bb684919.aspx

And an advanced one about Web Service - JavaScript - RenderPattern integration:
Using AJAX Jquery-like in the CAML of Custom Field Types
http://www.silver-it.com/node/34

And about custom web services:
Walkthrough: Creating a Custom Web Service
http://msdn.microsoft.com/en-us/library/ms464040.aspx
Creating a Custom Web Service for SharePoint
http://it.toolbox.com/blogs/sharepoint-blog/creating-a-custom-web-service-for-sharepoint-13553
SharePoint for Developers Part 6 Custom web services
http://blogs.msdn.com/kaevans/archive/2009/04/30/sharepoint-for-developers-part-6-custom-web-services.aspx

Hope that helps. Sounds to be not easy, but technologically possible.

Peter

Free Windows Admin Tool Kit Click here and download it now
November 23rd, 2009 1:39pm

Hi Peter,

This is a solution for sure.
The problem is that for every item in the list, the webservice will be called. Imagine that every users got 30 items in average in their libraries, the web service will be call 30 times for every page displaying the list (for every filter, every sort,...).

I'm sure that it is theoretically possible. But I'm not confident with the performance impact.
Tell me if I'm correct.

Thanks,
Py
November 23rd, 2009 2:44pm

Hi,

I agree with you, but that is not necessary. You can include the JavaScript block in the HeaderPattern, then your script iterates through all the items that are rendered by DisplayPattern where you should include the IDs only, aggregate the IDs into an XML for example, pass back the XML to your web service. It returns the response as ID-vti_sourcecontrollockexpires pairs (can be simple XML as well), then your script injects the short termcheck-out times for the IDs these are related to.

Alternative solution is to create a custom column for the files, and create a HttpModule that capture when a specific file is opened, and if the file has this custom column, then updates its value using the value stored in the vti_sourcecontrollockexpires property

About HttpModule:
Custom HttpModule Example
http://msdn.microsoft.com/en-us/library/aa719858(VS.71).aspx
HTTP Modules
http://msdn.microsoft.com/en-us/magazine/cc301362.aspx
HTTP Handlers and HTTP Modules in ASP.NET
http://www.15seconds.com/Issue/020417.htm
How To Create an ASP.NET HTTP Module Using Visual C# .NET
http://support.microsoft.com/kb/307996

Peter
  • Marked as answer by pyorg Monday, November 23, 2009 3:59 PM
Free Windows Admin Tool Kit Click here and download it now
November 23rd, 2009 3:22pm

Your imagination has no limit :-) Thanks.

For the first idea: it is still (more) complicated but seems now acceptable regarding performance.

For the second idea: Opening an office document is done through an activex. This activex call some webservices (We can see all the conversation with a proxy like fiddler). A webservice is also called when office is closed. So it should be possible to catch the opening and closing events.
The only problem left is when office or the OS client crash. No webservices is called. I should test with a job if the lock has expired or not.

Again thanks a lot.
I've now two solutions.
Py


November 23rd, 2009 3:59pm

Hi,

Thanks for your feedback!

"Your imagination has no limit"
Thanks! Unfortunately, my spare time has.I wish I would have time to implement 10% of the ideas I have in my mind. :-(

Let me know if the suggested approaches work or if you have further questions!

Peter
Free Windows Admin Tool Kit Click here and download it now
November 23rd, 2009 5:13pm

The relevant SPFile property for short term lock seems to be LockedByUser, LockExpires, etc.

April 28th, 2015 11:44pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics