开发者

How to get the Last Added Document ID in SharePoint using List.asmx

开发者 https://www.devze.com 2023-03-08 09:37 出处:网络
Actually I want to add the title and开发者_如何学运维 other fields value, but I don\'t have the Item Id? I am adding Document content using WebRequest. it added successfully, to add other information

Actually I want to add the title and开发者_如何学运维 other fields value, but I don't have the Item Id? I am adding Document content using WebRequest. it added successfully, to add other information title etc I am using Batch Element but it not do any change and If I pass ID manually, it set the values as expected.


After you call the Update method, you can grab the ID by using your SPListItem variable.

For example:

int newID = 0;
SPListItemCollection listItems = mySite.Lists["Friends"].Items;
SPListItem item = listItems.Add();

item["Title"] = "Joe Smith";

item.Update();
newID = item.ID;


The general approach would be to do a search on that list for the item with the most recent creation date. The problem of course is that someone else might add something to that list in the middle of your process.


I think the best way to manipulate items is to add an event receiver to the ItemAdding event to the list where you create content. In this event method you get the ID of the item and you can manipulate it before it will be saved to the list.

0

精彩评论

暂无评论...
验证码 换一张
取 消