使用 ListItem.Update() 的 SPItemEventReceiver 中的错误代码 -2130575305 (0x81020037)
我是 Sharepoint 的新手,目前正在维护一个有错误的既定解决方案。不幸的是我无法解决这个问题。当我尝试使用 properties.ListItem.Update() 方法时,我在 ItemAdded 事件中收到错误代码 2130575305 的 SPException。
似乎更新项目后不久就出现问题?
我尝试了在互联网上找到的所有内容,从在allowunsafeupdates上使用“ItemAdding”方法到disableeventfiring,但没有任何效果,现在我失去了动力
一小段程序代码:
SPListitem itm = list.GetItems(query).Add();
// all single line of text
itm["property"] = anotheritem["property" + "something" + itm["property"];
itm.Update();
然后在覆盖的ItemAdded中:
SPListItem itm = properties.ListItem;
itm["anotherproperty"] = "something different";
itm.Update(); // <- this throws the error
原始错误消息是德语,所以它不会对你有太大帮助,但它会说“SPException,请在浏览器中按回键并重试”,无论如何这都没有任何帮助。 另外,我不能在代码中使用 try catch,因为它似乎是某种网络异常?
抱歉 x0n,昨天我无法尝试您的回答。 它不起作用,不幸的是,属性中没有列表,只有 listid,即使我知道哪个列表调用 itemadded 事件并通过 lists["listname"].getitembyid(properties.listitem) 导航到它.id)
它不会工作。 难道“抓取新副本”正是我通过编写 splistitem itm =properties.listitem;
所做的吗? 有没有办法在 itemAdded 的开头“释放”该项目并在以后重用它?
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem itm = properties.ListItem;
itm["somefield"] = "sometext";
itm.Update(); // <- error, itm.SystemUpdate() throws the same error btw.
base.ItemAdded(properties);
}
我还阅读了msdn上的帮助,它只告诉我错误,但没有告诉我如何处理它,所以没有太大帮助。
关于brian的回答:如果 itemadded 已经是同步调用,那么应该没有问题吗?
I'm new to Sharepoint and I'm currently maintaining an established solution which has a bug. Unfortunately I cannot solve the Problem. I get an SPException with ErrorCode 2130575305 in the ItemAdded event when I try to use the properties.ListItem.Update() Method.
It seems like there is a Problem when updating a item shortly after it is updated?
I tried everything I found on the Internet, from using the "ItemAdding" method over allowunsafeupdates to disableeventfiring, but nothing worked, now I ran out of steam
A little piece of program code:
SPListitem itm = list.GetItems(query).Add();
// all single line of text
itm["property"] = anotheritem["property" + "something" + itm["property"];
itm.Update();
and afterward in the overridden ItemAdded:
SPListItem itm = properties.ListItem;
itm["anotherproperty"] = "something different";
itm.Update(); // <- this throws the error
The Original Error Message is in German so it won't help you much, but its saying something along "SPException, please press back in your browser and try again", which isn't of any help anyways.
Also, I can't use try catch in code as it seems to be some sort of web exception?
Sorry x0n, I couldn't try your answer yesterday.
it doesn't work, unfortunately, there is no list in properties, only a listid, and even if I know which list calls the itemadded event and navigate to it through lists["listname"].getitembyid(properties.listitem.id)
it won't work.
isn't "grapping a fresh copy" exactly what i did by writing splistitem itm = properties.listitem;
already?
Is there a way to "release" the item on the beginning of the itemAdded and reuse it later?
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem itm = properties.ListItem;
itm["somefield"] = "sometext";
itm.Update(); // <- error, itm.SystemUpdate() throws the same error btw.
base.ItemAdded(properties);
}
I also read the help on msdn, it only tells me the error but not how to handle it, so it wasn't much helpful.
About brian's answer: if itemadded already is the synchronous call there shouldn't be a problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您收到错误代码时,最好的资源是 MSDN 或 google。 - http://msdn.microsoft.com/ en-us/library/microsoft.sharepoint.client.listitem.update.aspx
错误代码表示该字段是只读的,这可能意味着很多事情。这可能是由于执行帐户的权限或简单的竞争条件造成的。
SharePoint 本质上会将大量更改排队,因此您肯定会遇到不同执行线程之间的计时问题。如果您要在同步事件(添加)中更改项目,然后在异步(添加)事件中再次更改项目,我强烈倾向于重新思考您实际尝试执行的操作的逻辑。
When you receive error codes the best resource is MSDN or google. - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.listitem.update.aspx
The error code means the field is read only, which could mean many things. This could be due to permissions of the executing account or a simple race condition.
SharePoint essentially queues up a lot of changes and therefore you can certainly run into timing issues between the different executing threads. If you are changing an item in a sync event(adding) and then again in the async(added) event I would strongly lean towards rethinking the logic of what you are trying to actually do.