lambda expressions in VB.NET... what am I doing wrong???
Posted
by Bob
on Stack Overflow
See other posts from Stack Overflow
or by Bob
Published on 2010-03-09T22:23:15Z
Indexed on
2010/03/14
23:05 UTC
Read the original article
Hit count: 203
when I run this C# code, no problems... but when I translate it into VB.NET it compiles but blows due to 'CompareString' member not being allowed in the expression... I feel like I'm missing something key here...
private void PrintButton_Click(object sender, EventArgs e)
{
if (ListsListBox.SelectedIndex > -1)
{
//Context
using (ClientOM.ClientContext ctx =
new ClientOM.ClientContext(UrlTextBox.Text))
{
//Get selected list
string listTitle = ListsListBox.SelectedItem.ToString();
ClientOM.Web site = ctx.Web;
ctx.Load(site,
s => s.Lists.Where(l => l.Title == listTitle));
ctx.ExecuteQuery();
ClientOM.List list = site.Lists[0];
//Get fields for this list
ctx.Load(list,
l => l.Fields.Where(f => f.Hidden == false
&& (f.CanBeDeleted == true || f.InternalName == "Title")));
ctx.ExecuteQuery();
//Get items for the list
ClientOM.ListItemCollection listItems = list.GetItems(
ClientOM.CamlQuery.CreateAllItemsQuery());
ctx.Load(listItems);
ctx.ExecuteQuery();
// DOCUMENT CREATION CODE GOES HERE
}
MessageBox.Show("Document Created!");
}
}
but in VB.NET code this errors due to not being allowed 'CompareString' members in the ctx.Load() methods...
Private Sub PrintButton_Click(sender As Object, e As EventArgs)
If ListsListBox.SelectedIndex > -1 Then
'Context
Using ctx As New ClientOM.ClientContext(UrlTextBox.Text)
'Get selected list
Dim listTitle As String = ListsListBox.SelectedItem.ToString()
Dim site As ClientOM.Web = ctx.Web
ctx.Load(site, Function(s) s.Lists.Where(Function(l) l.Title = listTitle))
ctx.ExecuteQuery()
Dim list As ClientOM.List = site.Lists(0)
'Get fields for this list
ctx.Load(list, Function(l) l.Fields.Where(Function(f) f.Hidden = False AndAlso (f.CanBeDeleted = True OrElse f.InternalName = "Title")))
ctx.ExecuteQuery()
'Get items for the list
Dim listItems As ClientOM.ListItemCollection = list.GetItems(ClientOM.CamlQuery.CreateAllItemsQuery())
ctx.Load(listItems)
' DOCUMENT CREATION CODE GOES HERE
ctx.ExecuteQuery()
End Using
MessageBox.Show("Document Created!")
End If
End Sub
© Stack Overflow or respective owner