Using Sharepoint Services Object Model to Create and Update Lists

Microsoft Sharepoint Services 3.0 provide a rich Object Model to work with sharepoint data and configuration. A good introduction can be found here.

The following code creates a sharepoint list ‘Application Errors’ if it does not exists and adds a List Item into the list.

Dim oSPSite As SPSite = New SPSite(“http://aleem:14433/”)
Dim oSPWeb As SPWeb = oSPSite.OpenWeb()
Dim listFlag As Boolean = True
oSPWeb.AllowUnsafeUpdates = True
Dim oSPErrorList As SPList = Nothing
Try
         oSPErrorList = oSPWeb.Lists(“Application Errors”)
Catch ex As Exception
         listFlag = False
End Try
If listFlag = False Then
         oSPWeb.Lists.Add(“Application Errors”, “Application 
         Errors”, SPListTemplateType.CustomGrid)
         oSPErrorList = oSPWeb.Lists(“Application Errors”)
         oSPErrorList.Fields.Add(“Error Details”,
         SPFieldType.Note, True)
          oSPErrorList.Update()
End If
Dim oListItem As SPListItem = oSPErrorList.Items.Add()
oListItem(“Title”) = “Application Error”
oListItem(“Error Details”) = strErrorMessage
oListItem.Update()
oSPWeb.Dispose()
oSPSite.Dispose()

Windows sharepoint Services also provide different webservices to manage its data and configuration. More information here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s