Answered by:
Problem about SPFile.SPCheckOutStatus.ShortTerm

Question
-
Dear all,
I have a question about SPFile.SPCheckOutStatus.ShortTerm, I know that it specifies that the file has been opened by a user and is locked for editing.
Now, I have an infopath linking to a workflow. Once I modified the infopath and submit to sharepoint again, the infopath will have the status SPFile.SPCheckOutStatus.ShortTerm. So when I open the infopath again with other user account, it will alert that "The form cannot be filled out because you do not have adequate permissions, another user has the form open, or the form is open in another program. Do you want to open a read-only copy of the form?"
Should I do anything to change the status of the infopath from ShortTerm to None so that I can edit the infopath with other user account?
Please help.
Thanks,
Ray
Thursday, November 17, 2011 9:08 AM
Answers
-
Hi Ray,
Infopath (and any other office app) would take a short term lock (i.e. for the life that the application is open) if a user opens a form for editing. So ideally the lock should be released once the form is closed.
Try this approach as well.
You can directly update the file lock in SQL on the Sharepoint Database
First open SQL Server Management Studio and connect to the database server hosting the WSS database. Connect to the Sharepoint content and versioning database (WSS_Content_*)
It is now necessary to modify the contents of the Alldocs table. The AllDocs Table stores data for all documents in the content database.
So, run a query against the Alldocs table:
Select * From Alldocs Where LeafName like '%filename%'
Then perform a sql update on the needed file:
Update Alldocs set CheckoutUserID = null, NextToLastTimeModified = null where LeafName = 'filename'
The above Query is another approach else my suggestion would to use my last post code.Even I'll try to investigate more possible reasons for this scenario.
Thanks, Ali YasirFriday, November 18, 2011 8:01 AM
All replies
-
Hi Ray,
As per the rules of SPCheckOutStatus.ShortTerm ,
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.
Incase if One User did not check in the file and the 2nd User who did check out the file could not do it either.
So refer the following 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("SiteUrl"); 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.ShortTerm || 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();
Let me know if above case helps you.
Moreover, did you get a chance to check out what is the "Checked Out To" column contains. Does it holds any value whenever you go and try checking out the form ?
Thanks, Ali Yasir- Proposed as answer by Sachin Dagar Thursday, November 17, 2011 10:54 AM
Thursday, November 17, 2011 10:02 AM -
Hi Ali Yasir,
Thanks.
But in my case, I have already close the document. I have tried to use the method "submit to sharepoint" or directly close the infopath. Then the onworkflowunderchanged event in the workflow detect there is changes in infopath and run the necessary code. However, it detects that the status of the infopath is under shortterm.
My question is that if the method I close the infopath is not correct so the workflow still detects that the infopath is under shorterm? Or is it normal that the workflow will detect shorterm status for the infopath even the user has closed the document and I should check in the document by programming code as mentioned above?
Thanks again,
Ray
Friday, November 18, 2011 1:55 AM -
Hi Ray,
Infopath (and any other office app) would take a short term lock (i.e. for the life that the application is open) if a user opens a form for editing. So ideally the lock should be released once the form is closed.
Try this approach as well.
You can directly update the file lock in SQL on the Sharepoint Database
First open SQL Server Management Studio and connect to the database server hosting the WSS database. Connect to the Sharepoint content and versioning database (WSS_Content_*)
It is now necessary to modify the contents of the Alldocs table. The AllDocs Table stores data for all documents in the content database.
So, run a query against the Alldocs table:
Select * From Alldocs Where LeafName like '%filename%'
Then perform a sql update on the needed file:
Update Alldocs set CheckoutUserID = null, NextToLastTimeModified = null where LeafName = 'filename'
The above Query is another approach else my suggestion would to use my last post code.Even I'll try to investigate more possible reasons for this scenario.
Thanks, Ali YasirFriday, November 18, 2011 8:01 AM -
Hi Ali Yasir,
Thanks. I am possible to open the infopath after using the sql to update the check out status. However, the check in function does not work.
Thanks,
Ray
Thursday, November 24, 2011 7:49 AM -
IMHO working ON the DB level is not good idea - there's a chance of doing something very bad :P You should do this only if there's no other way.Thursday, November 24, 2011 11:46 PM
-
Hi,
Thanks.
But I cannot find other way to solve the problem.
My problem is that there are two groups of user, let's define them as user A and user B.
After user A has modified the infopath document, I have to remove the permission of user A and add the permission of user B to the infopath through the workflow.
However, the problem occurs, even the infopath is closed, when I open the infopath by user B account, there is error that "The form cannot be filled out because you do not have adequate permissions, another user has the form open, or the form is open in another program. Do you want to open a read-only copy of the form?"
The problem will not occur if I don't remove the permission of user A. But I really have to remove the permission of user A.
So the solution is to update the check out status by sql. Is there other way to solve the problem?
Thanks,
Ray
Friday, November 25, 2011 3:37 AM -
Hi Ray,
Did you find a way to resolve this issue without changing the database table(Alldocs) directly? I'm trying to fix this issue using the SharePoint API but couldn't find any. please let me know what you ended up doing.
Thanks
RV
Thursday, December 8, 2011 2:05 AM -
Hello,
I feel it is important to mention that under no circumstances should you EVER make direct modifications to the SQL database. This will leave your SharePoint database in an "unsupported" state and is fraught with danger. Even running SELECT queries is a bad idea.
I believe (correct me if I'm wrong) the ShortTerm enum means that an application has the file checked out, and the application needs to continue to renew the short term check out.
You could use your code in the InfoPath form to check in the file after save and before closing.
Is "required checkout" turned on for the library?
Cheers,
George Begbie | Software Consultant | MCTS SharePoint 2010 Application Development
Sunday, April 22, 2012 1:01 AM -
from 2010, 2013, SPI of sharepoint support you release look of spfile object. YOu can release look by method
SPFile.ReleaseLock(SPFile.LoclkId)
please check status of file before release lock.
Friday, January 11, 2013 5:59 AM