Sharepoint from the Domino Developer perspective : Part 2

After a week of nose down development in the Sharepoint 2007 environment, I came away with a greater appreciation for how similar Domino and Sharepoint are in their mechanics, and a certain fondness of the simplicity behind the facade of Sharepoint complexity.


As I mentioned in a previous article, the Sharepoint lists, views, and document libraries have many similarities to their Domino equivalents. Although their may be some syntactical differences in how they are manipulated, Microsoft has done an excellent job in making lists very easy to work with by eliminating all the complex joins and table relationships that accompany typical web client server development.

For example, I can create a list of contacts where I have a dropdown list of users names, and these names come from another “user” list. When I access the contacts list, I do not need to know anything about how the two lists are related, when I access the “username” column of the contacts list, I get a name, not a reference to another table.

The other interesting mechanism at work is how so many other Sharepoint entities are built off of this basic list concept. For example, the Document library is nothing more than a list with pre-defined columns to manage check-in, check-out, and a BLOB to store the document. I am continually amazed at how many things can be boiled down to a list with custom fields.

Another nicety is the event handler model of Sharepoint. A Domino developer typically writes a history/audit function into every application that keeps a trail of changes and who made them. With Sharepoint, you attach the event handlers to the various lists, and when anything is added/changed/deleted, you can write audit information into another list.

The biggest difficulty at this point is the lack of good documentation and examples, not to mention some sample code that leads you down a bad track. For example, all of the documentation examples use hard coded url’s to instantiate connections to lists and sites. Yet, when you attempt to deploy your user control to Sharepoint site, it will fail unless you use the proper method which uses the context of the control.

The examples look like this:


    Dim theSite As SPSite = New SPSite("http://serverAddress")
    Dim theWeb As SPWeb = theSite.AllWebs("ApplicationName")
    Dim theList As SPList = theWeb.Lists.Item("ListName")

Yet if you attempt to deploy a user control with these hard coded values, you will get all kinds of cryptic errors. The proper way looks like this:


    Dim theWeb As SPWeb = SPContext.Current.Web
    Dim theList As SPList = theWeb.Lists.Item("ListName")

Not too much of a difference between VB.NET and LotusScript. Here is side by side comparison of of how to get a single field value from a Sharepoint list, given a unique value, and the LotusScript code to do the same.

VB.NET


    Dim theWeb As SPWeb = SPContext.Current.Web
    Dim theList As SPList = theWeb.Lists.Item("MyList")
    Dim listItem As SPListItem = Nothing
    Dim theQuery As New SPQuery
    theQuery.Query = "<Where><Eq><FieldRef Name=""ID" /><Value Type=""Text"">100</Value></Eq></Where>"
    Dim theColl As SPListItemCollection = theList.GetItems(theQuery)
    If theColl.Count > 0 Then
        listItem = theColl.Item(0)
        strAppId = listItem("ApplicationId")
    End If

LotusScript


    Dim s As New NotesSession
    Dim db as NotesDatabase
    Dim vw As NotesView
    Dim doc as NotesDocument
    Set db = s.CurrentDatabase
    Set vw = db.GetView("myView")
    Set doc = vw.GetDocumentByKey("100")
    If Not(doc Is Nothing) Then
        strAppId = doc.ApplicationId(0)
    End If

Since the Sharepoint lists do not function on the idea of key columns, you can find a list item based upon the value of any field. Notice the Sharepoint query language? That’s right, Microsoft just had to introduce ANOTHER query language to the never ending list we have already. This language is called CAML (Collaborative Application Markup Language), and there is a tool called the CAML Builder which creates the queries for you.

Writing to a Sharepoint list is just as easy:


    listItem = theColl.Item(0)
    theWeb.AllowUnsafeUpdates = True
    listItem.Item("Status") = "Complete"
    listItem.Item("AssignedTo") = ""
    listItem.Update()
    theWeb.AllowUnsafeUpdates = False

Here is how you can read a text file directly from a Sharepoint document library:


    Dim contentString As String
    Dim theFolder As SPFolder = theWeb.GetFolder(theWeb.Url + "/LibraryName/" + someIdValue + "/misc")
    Dim theFile As SPFile = Nothing
    For Each theFile In theFolder.Files
        If theFile.Name = "rcpt-" + someIdValue + ".txt" Then
            Dim byteArray As Byte() = theFile.OpenBinary
            Dim enc As New System.Text.ASCIIEncoding()
            contentString = enc.GetString(byteArray)
            Exit For
        End If
    Next

Over the following weeks we should be getting more into the security model which is not quite as easy as Domino’s, but it does offer some additional flexibility that Domino lacks.

Anyway, I can definitely say that Sharepoint has come a long way since its early versions, and is bringing some incredible power to the table that Domino developers should have an easy time mastering.

4 Responses to “Sharepoint from the Domino Developer perspective : Part 2”

  1. Ferdy Says:

    It is simply amazing how you keep coming up with articles that perfectly match my current needs. Well done, and here’s to many more!

  2. Administrator Says:

    LOL! I am here to serve Ferdy.

  3. ivax Says:

    Hi,
    one question!! in this code..

    listItem = theColl.Item(0)
    theWeb.AllowUnsafeUpdates = True

    listItem.Item(”Status”) = “Complete” //What about if “status” isn’t an string, how I put an item of combo(with values Complet, Medium or another)?????

    listItem.Item(”AssignedTo”) = “”
    listItem.Update()
    theWeb.AllowUnsafeUpdates = False

  4. Administrator Says:

    In our application the status field is a drop down list of keywords (Ready / Assigned / Complete / Hold). If the values in your drop down come from another list, you need to use the Sharepoint list ID in your code. If you were to look in the source code of a sharepoint page with your list of drop-down values, you can see that each value in the drop-down has an alias/value associated with the text.