vb.netsharepointcaml

VB Caml Query is not working properly (Sharepoint List to Table)


my problem is as following.

I have a sharepoint list with people who are flagged oof (out of office) that I want to populate a table on a website with to show all of these people.

There is a date picker so that only people that are oof on that day are shown. But the query is not working properly.

   Try

        Dim userNameSP As String = My.Settings.user

        Dim password As String = My.Settings.passwort

        Dim secureString As SecureString = New NetworkCredential("", password).SecurePassword

        Dim cred = New SharePointOnlineCredentials(userNameSP, secureString)
        Dim clientContext As New ClientContext(siteUrl)
        clientContext.Credentials = cred
        Dim web As Web = clientContext.Web
        Dim oWebsite As Web = clientContext.Web
        Dim collList As ListCollection = oWebsite.Lists

        Dim oList As List = collList.GetByTitle("List")
        Dim camlQuery As CamlQuery = New CamlQuery()
        camlQuery.ViewXml = "<Query><Where><Eq><FieldRef>Name ='Email'</FieldRef><Value Type= 'Text'>my@mail.com</Value></Eq></Where></Query>"
        Dim collListItem As ListItemCollection = oList.GetItems(camlQuery)

        clientContext.Load(collListItem)

        clientContext.ExecuteQuery()

        For Each item In collListItem
            DataGridView1.Rows.Add(item("Title"), item("field_2"), "-") ' item("field_6"))

        Next
    Catch ex As Exception
        Console.WriteLine(ex.Message)
    End Try

This is the code.

The query just does nothing. (Gives out the whole list)

I have a column named "Email" in my sharepoint list and my mail is in there.

I've tried multiple queries copied from the internet, just changing the names of the variables. I either get the whole list or nothing at all, sometimes with, sometimes without error.

The only usable error was: "value does not fall within the expected range"


Solution

  • Soo, just found out the answer to this.

    To get the right query, i needed to put "Name = 'field_1' inside the bracket as @mamift mentioned.

    To filter my entries, i needed the "view" tag.

    <View><Query><Where><Eq><FieldRef Name ='field_1'></FieldRef><Value Type= 'Text'>my@mail.com</Value></Eq></Where></Query></View>
    

    field_1 is the real name of the column, "Email" does nothing in Sharepoint Online.
    (Columns are named field_* , with * being the number of the row, counting from left. Except for Title, which is named "Title")