I'm developing an application using Silverlight 5, Visual Studio 2010 and VB.Net.

I've reached the stage where I have a requirement to read and write information to a Sharepoint Online list, but I'm really struggling to get my head round how I should do this.

There seem to be at couple least a couple of methods:

  1. Using Lists.asmx - I have added this as a Service Reference, but it doesn't seems to have made available some methods (?) I would expect to see. i.e. intellisense sees lots of GetListItems* methods, but not plain old GetList. Where am I going wrong?

  2. Alternatively, I think I can install the Silverlight Client Object for Sharepoint 2010 and use this? But again I'm not really sure where to start.

Can anybody advise me as to which way I should be leaning, and perhaps give me pointers to start me off.




Ok first you need to configure SharePoint Foundation 2010 for your development machine so you can have the Silverlight 5 SharePoint Client Object Model you can find that here.


Next after you have completed that use the below link on how to use the Silverlight OM.


Below is sample code

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Net
     Imports System.Windows
    Imports System.Windows.Controls
    Imports System.Windows.Documents
    Imports System.Windows.Input
    Imports System.Windows.Media
    Imports System.Windows.Media.Animation
    Imports System.Windows.Shapes
    Imports Microsoft.SharePoint.Client

    Namespace Microsoft.SDK.SharePointServices.Samples
Partial Public Class MainPage
    Inherits UserControl
    Private oWebsite As Web
    Private collList As ListCollection
    Private listInfo As IEnumerable(Of List)

    Public Sub New()
    End Sub

    Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim clientContext As ClientContext = ClientContext.Current
        oWebsite = clientContext.Web
        Dim collList As ListCollection = oWebsite.Lists

        clientContext.Load(oWebsite, Function(website) website.Title)

        listInfo = clientContext.LoadQuery(collList.Include(Function(list) list.Title, Function(list) list.Fields.Include(Function(field) field.Title).Where(Function(field) field.Required = True AndAlso field.Hidden <> True)))

        clientContext.ExecuteQueryAsync(AddressOf onQuerySucceeded, AddressOf onQueryFailed)
    End Sub

    Private Sub onQuerySucceeded(ByVal sender As Object, ByVal args As ClientRequestSucceededEventArgs)
        Dim updateUI As UpdateUIMethod = AddressOf DisplayInfo
    End Sub

    Private Sub onQueryFailed(ByVal sender As Object, ByVal args As ClientRequestFailedEventArgs)
        MessageBox.Show = "Request failed. " & args.Message & vbLf & args.StackTrace
    End Sub

    Private Sub DisplayInfo()
        MyOutput.Text = "Title: " & oWebsite.Title
        collList = oWebsite.Lists

        For Each oList As List In listInfo
            MyOutput.Text += vbLf & vbTab & "List: " & oList.Title

            Dim collField As FieldCollection = oList.Fields
            For Each oField As Field In collField
                MyOutput.Text += vbLf & vbTab & vbTab & "Field: " & oField.Title
            Next oField
        Next oList
    End Sub

    Private Delegate Sub UpdateUIMethod()
End Class
End Namespace


One more Important Detail about the ClientContext. If you use ClientContext.Current your silverlight application has to be ran within a silverlight web part to work. To access a specific site instantiate your context like below.

     Private ReadOnly Property ClientCtxt As Microsoft.SharePoint.Client.ClientContext
        If clientContext Is Nothing Then
            ' clientContext = New ClientContext("http://1mem8400:25775/FTP/Engineering/NPI")
            clientContext = Microsoft.SharePoint.Client.ClientContext.Current
        End If
        If clientContext Is Nothing Then
            Throw New Exception("SharePoint Connection Failed")
        End If
        Return clientContext
    End Get
End Property
| improve this answer | |
  • Joseph, thanks for the reply. So this is going with the 2nd method I mentioned, I assume? I already have the Sharepoint Foundation Client Object stuff from here microsoft.com/en-us/download/details.aspx?id=21786 so I will try your code. – finisterre Oct 9 '12 at 14:44
  • Ok that is great look at my edit for the gotcha. I don't think that was specified in the MSDN article. – Joseph D Surgeon Oct 9 '12 at 15:02
  • Another thing I wouldn't Access the Lists.asmx service that is for older applications. You can use the rest interface if you want to use a different client. But if your using Silverlight nothing can beat the simplicity of the OM Microsoft Created. – Joseph D Surgeon Oct 9 '12 at 16:37
  • If I'm using the Client Object Model does my Silverlight app need to run with elevated trust? Thanks. – finisterre Oct 10 '12 at 8:57
  • Nope but you do need a ClientAccessPolicy in the sharepoint IIS website root folder for it to work. stackoverflow.com/questions/2302825/… – Joseph D Surgeon Oct 10 '12 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.