An user asked me if I could take care of a document that was locked, being the sharepoint administrator that I am, I figured this could be solved by checking in the document and discard the changes. But Sharepoint told me that the document was not checked out and if I wanted to check it out it gave the following error :
"The file [filename] is checked out or locked for editing by [username]"
After some googling I found out that there were two types of checking-out:
Long term check out
This is the explicit check out .
This holds a lock on the document whether you have it open for edit or not.
Short term check out
You get this feature implicitly.
If you open a document for editing, you get a short term lock on the document to prevent other people from editing the doc while you are.
The Office client applications refresh this lock periodically as long as you keep the document
open. Once you close the document, your short term check out is released
Kudos to Mike Walsh's FAQ for the info!
Also, mentioned in the following KB-article, if your application crashes a short term lock of 10mins will occur
Unfortunatly I could not check in the file and the user who did check out the file could not do it either.
So I wrote some code to force the check-in.. only problem is that a new version will be written and the 'modified date' and 'modified by' metadata will be overwritten.
SPSite mySiteCollection = new SPSite("teamsitelink");
SPWeb web = mySiteCollection.RootWeb;
SPListCollection lists = web.Lists;
foreach (SPList list in lists)
{
if (list.Title == "Document Library")
{
SPListItemCollection docLibItems = list.Items;
foreach (SPListItem docLibItem in docLibItems)
{
if (docLibItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.LongTerm)
{
Console.WriteLine(docLibItem.File.Name.ToString());
try
{
docLibItem.File.CheckIn("");
}
catch (Exception error)
{
Console.WriteLine(error.Message.ToString());
}
}
}
}
}
web.Dispose();
mySiteCollection.Dispose();