Adding item to sharepoint 2003 SPList Programmatically

Online project management, task software, and free collaboration workspace: AJAXWorkspace
AJAXWorkspace is a free online workspace that offers task tracking software, team collaboration, online calendar, document sharing, and file management for project management and teamwork.

I come accross some problems when adding new item to a SPList. The error i got is “Value does not fall within the expected range. ” This would only happen if you target list is empty. After do some googling, this seems is MS known bugs. Luckly there is workarround to solve this issue. Simple rules is

1. Add a new item, assign “Title” item and save it

2. Get the newly created item and update it with remaining items.

Here are the codes:

SPListItem newListItem = spList.Items.Add();

newListItem["Title"] = “The title”;

newListItem.Update();

SPListItem existingListItem = spList.GetItemByID(newListItem.ID);

existingListItem[2] = “Category 1″;

existingListItem.Update();

P/s: You only need to add new item as in this way for the empty SPList. Once u have at least one item.. the error will gone.

Please visit the original article: http://blog.buro9.com/2007/02/26/sharepoint-splistitem-quirks for more information…

Posted in .Net, SharePoint.

2 Responses to “Adding item to sharepoint 2003 SPList Programmatically”

  1. MOSS Page Setting Error - Value does not fall within the expected range « yyTech Blog on .Net, SQL, SharePoint, Collaboration and tech tips. Says:

    [...] when try to change the “Page Setting” in MOSS 2007. Yes, again same error message as in here (In fact, this error occurs is various scenarios). This error only happens when you copy an aspx [...]

  2. chanaka Says:

    nice, thanks
    it works

Leave a Reply