I'm using VB.Net 4.0/Silverlight 5 and the SharePoint Client Object Model. I have SharePoint Foundation 2010 running on localhost.
I've been trying for days to read some values from a list, with no success.
I have a List called 'pfa'. The list has 3 columns; FullName, JobTitle and PhoneNumber.
I just need some sample code to read the items from the list and display them in a textbox.
Can anyone help? My latest code is below. And, this is just attempting to read the Id: field for now.
Thanks,
JT
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
Imports SP = Microsoft.SharePoint.Client
Namespace Jason
Partial Public Class MainPage
Inherits UserControl
Private oWebsite As Web
Private collList As ListCollection
Private collListItem As ListItemCollection
Private listInfo As IEnumerable(Of List)
Public Sub New()
InitializeComponent()
End Sub
Private Sub onQuerySucceeded(ByVal sender As Object, ByVal args As ClientRequestSucceededEventArgs)
MessageBox.Show("Request Succeeded")
Dim updateUI As UpdateUIMethod = AddressOf DisplayInfo
Me.Dispatcher.BeginInvoke(updateUI)
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()
Dim oListItem As SP.ListItem
For Each oListItem In collListItem
MyOutput.Text += vbLf & "Id: " & oListItem.Id
Next oListItem
End Sub
Private Delegate Sub UpdateUIMethod()
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim clientContext As ClientContext = clientContext.Current
Dim oList As SP.List = clientContext.Web.Lists.GetByTitle("pfa")
oWebsite = clientContext.Web
Dim _Query = SP.CamlQuery.CreateAllItemsQuery
Dim collListItem As ListItemCollection = oList.GetItems(_Query)
clientContext.Load(collListItem)
clientContext.ExecuteQueryAsync(AddressOf onQuerySucceeded, AddressOf onQueryFailed)
End Sub
End Class
End Namespace