One query at a time on a SharePoint list
I have a small application that uses a SharePoint list as the data source. This application has to be used by many users at the same time. There may occur a situation when more than one user woult want to edit the same list item of the SharePoint list. And that's开发者_运维知识库 not the way the application is intended to work. I need to modify the way the application accesses the list so that there will be one query at a time and the conflict would not occur. How can i do it?
assuming all the users of the list will only access it through your application, could you synchronize access to the lie using a "lock" file that your application creates, similar to the way MS Access uses a .ldb file to manage concurrent access. The lock file would contain the name of the application instance/connection/computer that was currently accessing the list, and the application would check to see if a lock file existed before accessing the list.
Without more specifics I have to say this strikes me as 'code smell' and you may be better off looking at your applications design/architecture.
A more helpful suggestion is to use version control and 'requires checkout' on your list as the locking mechanism.
If you are operating against a list, check the modification date and/or the version umber before you save, if it's different than the date or version in the client's copy then notify the user.
If your list is is a form or document librry your endeavor is much easier, check the file out when the user opens it. I would set a timeout just in case somebody's app crashes or they close the lid on their laptop before you have a chance to clean up.
SPListItem.File.CheckOut()
Or, you could check to see if the files is checked out before you check it in
SPListItem.File.CheckedOutBy
SPListItem.File.CheckedOutExpires
精彩评论