Post navigation

Insert into a SharePoint List using ASP.Net

This post describes how to insert into a SharePoint list using ASP.Net. First add a reference to the SharePoint DLL for your specific version. I’m working with SharePoint 2010, and the DLL can be found in the following location:

Now I’ve just dumped some example code below, which inserts into a Text field (obtained from a Textbox), a Multi choice field (obtained from a CheckList box) and a User field (obtained from a SharePoint PeopleEditor control). I’ve also left a few comments in intentionally, as I tried different ways of doing things. I found that if I ran this chunk of code with elevated privileges it inserted the entry into the list but didn’t trigger the associated workflow. I also tried to run it as an impersonated user, but it still didn’t trigger the workflow. So I commented out the RunWithElevated privileges line and it all worked well – the list item inserted and the associated workflow triggered.

You can also see that for the list name, I store this in the Web.Config file since I use the same list throughout the site.