Playing with SharePoint Custom Lists Using SPList Class (SharePoint Object Model)
As a developer you can access SharePoint content using either Microsoft.SharePoint.dll (SharePoint Object Model) or web services. In this post I will be discussing the access using the object model and in the next post I will explain it using web services and JavaScript as well.
Let’s elaborate together more about a Site Collection Structure:
Summing up our theory: In order for us to access a custom list, we must first create 3 objects, one that points to the site collection that contains the site that contains the custom list; then create a second object that points to the site that contains the custom list, and finally a third object that points to the custom list.
Moving now to the fun part, In order for us to understand this more, let’s create a custom list with 2 fields: Shisha (Huka or Hubbly Bubbly) Flavor Name and Flavor Rating.
Now let’s creae a new webpart and call it Shisha Flavor Rating Form. We will use this webpart to add new list items to our custom list.
Now we will start by defining the controls that we will access globally:
We will access both text boxes and label from the button event handler. Moving on we define the controls we need to use in the UI and place that code inside the CreateChildControls function:
If you try building and deploying the web part it will look like below:
To make our web part work we need to add some logic and implement the event handler:
The event handler is really simple. First we create an object that points to a site collection called http://decisionware.local. Then we create another that points to a site called i-bander which exists under the http://decisionware.local site collection. Finally we create an object that point to our custom list that we created previously called “Shisha Flavor Rating”. To add a new list item we create an object of type SPListItem, fill in the column values, and finally call the Update method which will write back to the list.
Let’s test our code:
If you are interested in playing with the source code you can download it from here.








I have been a gamer since I was 8 back on the Atari
Love the article. XBOX 360
can you write about web services? a screen cast would be nice
can you do an example using web services?
+1
check this as well http://www.youtube.com/watch?v=QAdr_gbeGa0&feature=related
This is very handy. Web Services example please