sharepoint splititem.更新失败
我有以下代码:
using(SPWeb web = ...
{
....
SPListItem item = GetItemById(id);
item["Status"] = status;
item["Reason"] = reason;
item.Update();
}
我得到了一个异常“无法完成此操作”...但是,试图弄清楚它,我注意到一些...奇怪...
我在行 item.Update( )...在调试时,我让异常发生,然后我转到我的监视窗口并放在那里“item.Update()”...该项目已更新...
然后..我重新开始,但是,这一次,我在监视窗口中尝试了“item.Update()”,抛出了异常。然后我按 F10 执行我的代码,令我惊讶的是它成功更新了该项目。
我已经尝试了一遍又一遍,并且总是相同...所以,出于某种奇怪的原因,第一次失败并且第二个很好..有人知道为什么吗?
编辑:
我已经尝试过:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
....
item.Update();
});
但是,它仍然失败,现在例外:“由于当前状态,操作无效”...
编辑2:
这是 moss 2007,它是一个连接到共享点站点的 Web 应用程序(asp.net),两列都存在..
我发现了另一件事..如果我在 item.Update() 中放置一个断点,然后按 F10 ,它有效..该项目已更新..并且没有抛出异常...但在正常执行中,它总是失败..
I have the following code:
using(SPWeb web = ...
{
....
SPListItem item = GetItemById(id);
item["Status"] = status;
item["Reason"] = reason;
item.Update();
}
And I got an exception "Cannot complete this action"... however, trying to figure it out, I noticed something... weird...
I put a breakpoint exactly in the line item.Update()... while debugging I let the exception to happen, and then I went to my Watch window and put there "item.Update()"... the item was updated...
Then.. I started all over again, but, this time, I tried "item.Update()" in the watch window, an exception was thrown.. then I press F10 to execute my code, and for my surprise it successfully updated the item..
I have tried this over and over, and always is the same... so, for some weird reason, the first time it's failing and the second one is good.. does anybody know why?
EDIT:
I've tried this:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
....
item.Update();
});
But, it still fails, now with the exception: "Operation is not valid due to the current state"...
EDIT 2:
this is moss 2007, it is a web application (asp.net) connecting to a sharepoint site, both columns exist..
I've found another thing.. if I put a breakpoint in item.Update(), and I press F10, it works.. the item is updated..and no exception is thrown... but in normal excecution, it always fails..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试设置:
此外,如果您在此之前对 SPWeb 对象或 SPListItem 对象进行其他更新,则可能需要再次更新它们。
请在此处查看一些可能对您有帮助的信息:
http://hristopavlov.wordpress。 com/2008/05/16/what-you-need-to-know-about-allowunsafeupdates/
Try setting:
Also, if you make other updates before this on the SPWeb object or SPListItem object you might need to new them up again.
Check here for some information that might help you:
http://hristopavlov.wordpress.com/2008/05/16/what-you-need-to-know-about-allowunsafeupdates/