(1) var list1 = web.GetList("/lists/list1");
(2) var item1 = list1.GetItemById(10001);
(3) ...在此处设置断点,打开ID = 10001的项目进行编辑,更改“标题”字段并保存。然后运行下面的代码:
(4)item1[SPBuiltInFieldId.Title] = "some text";
(5)item1.Update();行(5)抛出保存冲突异常。
如何在第(3)行锁定项目进行编辑?或者任何其他避免冲突的方法?
发布于 2011-09-23 01:43:31
您必须手动检查SPListItem
try
{
var item = list.GetItemById(3);
item["MyField"] = "FooBar";
item.Update();
}
catch(SPException conflictEx)
{
// handle conflict by re-evaluating SPListItem
var item = list.GetItemById(3);
// ..
}我不知道还有其他的自动取款机。
发布于 2013-06-06 03:45:35
// *为每个列表修改创建一个新的SPWeb对象,否则我们将看到保存Conflict*
从以下URL http://platinumdogs.me/2010/01/21/sharepoint-calling-splist-update-causes-save-conflict-spexception/
例外情况
using (var thisWeb = featSite.OpenWeb(featWeb.ID))
{
try
{
var listUpdate = false;
var theList = thisWeb.Lists[att.Value];
// change list configuration
// .....
// commit List modifications
if (listUpate)
theList.Update();
}
catch
{
// log the event and rethrow
throw;
}
}
}
}发布于 2011-09-23 03:46:16
另一种方法是使用Linq to SharePoint,Linq to SharePoint为您提供了一种冲突解决机制
https://stackoverflow.com/questions/7516553
复制相似问题