确定 MOSS SPList 中的下一个 SPListItem ID?
我正在尝试确定要在 MOSS 列表中创建的下一个列表项的 ID。 有什么办法可以做到这一点吗?
谢谢,魔法安迪
I am trying to determine what the ID of the next list item to be created in a MOSS list will be. Is there any way of doing this?
Thanks, MagicAndi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下 CAML 查询将确定接下来最有可能生成的 ID:
但是,这对于删除最近生成的列表项(ID N)的情况不起作用,然后我们使用上面的代码给出下一个ID - 它将返回 N,而它应该是 N+1。
The following CAML query would determine the most likely ID to be generated next:
However, this does not work for the case where the most recently generated list item (with ID N) is deleted, and we then use the above code to give the next ID - it will return N, when it should be N+1.
看这个链接: http://snipplr.com/view/ 24210/next-splistitem-id-from-splist/,我尝试过这个解决方案,它确实克服了其他缺点,它涉及查询 WSS 内容数据库,这可能会贵一点,但你可以实现混合解决方案,仅当 colItems.Count == 0 在其他逻辑之后才查询数据库。
问候!
Look at this link: http://snipplr.com/view/24210/next-splistitem-id-from-splist/, I have tried this solution and it does overcome the other shortcomings, it involves querying the WSS content DB which can be a little bit more expensive, but you could implement a hybrid solution, where you would query the DB ONLY if colItems.Count == 0 after the other logic.
Regards!
如果您想更加确定,可以创建一个列表项,记录其 ID,删除该列表项,下一个列表项将具有 ID+1。 这应该可以克服最后一项被删除的情况。
当然,这非常简单……但从内容数据库读取也是如此。
我可以问一下为什么需要它吗? 或者,您可以将包含 GUID 的列添加到列表中,以便您可以自己预先生成 ID。
If you want to be more sure you can create a listitem, record its ID, delete the list item and the next listitem will have ID+1. This should overcome the case where the last item was deleted.
Of course this is quite uqly.. but so is reading from the content database.
May I ask why you need it? Alternatively you can add a column to your list that contains a GUID so you can pre-generate ID's yourself.
我找到了解决这个问题的另一种方法。
我遇到的问题与版本有关:
我的列表中有版本控制,但不想创建新项目的两个不同版本。
像这样解决它:
人们可能认为关闭版本控制会删除除当前版本之外的所有版本,但事实并非如此。
这不会为您提供下一个 ID,但可能会解决某人的根本问题。
I found another solution to this problem.
The problem I had was related to versions:
I had versioning on my list but didn't want to create two different versions of my new item.
Solved it like this:
One might think that turning versioning off would erase all versions except the current but it doesn't.
This doesn't give you the next ID but might solve the underlying problem for someone.