BreakHead
BreakHead

Reputation: 10672

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

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.

Upvotes: 1

Views: 1848

Answers (3)

Andrew McCauley
Andrew McCauley

Reputation: 11

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;

Upvotes: 1

elsni
elsni

Reputation: 2053

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.

Upvotes: 0

Mark Mascolino
Mark Mascolino

Reputation: 2292

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.

Upvotes: 0

Related Questions