Reputation: 3
I want to add items to a still existing SharePoint list by self-coding.
So I searched the internet and found a lot of information how to create lists, add items and so on..
SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists[TextBox1.Text].Items;
SPListItem item = listItems.Add();
The coding seems easy, but where i have to put the code? I programmed Web Parts and deployed these to my web application. This was no problem, but here i am missing an approach.
I am using VisualStudion 2008 and SharePoint WSS 3.0
Thank you for any help.
Upvotes: 0
Views: 5638
Reputation: 544
you are doing some modification on site ...so after that we need to update the site ..Use ListItem.update();
Upvotes: -1
Reputation: 33511
It depends on the purpose - why are you doing this?
Upvotes: 2
Reputation: 448
SPWeb app = SPContext.Current.Web;
SPList ListName = app.Lists["YourListName"];
SPListItem ListItem = ListName.Items.Add();
ListItem["field1Name"] = value;
ListItem["field2Name"] = value;
ListItem.Update();
Upvotes: 4