views:

51

answers:

2

I have the following code, which is a modified version from MSDN's website, to test getting all list items where the field "UserID" matches the value specified:

Dim xmlDoc = New System.Xml.XmlDocument()

        Dim ndQuery As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "")
        Dim ndViewFields As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "")

        ndQuery.InnerXml = <Query>
                               <Where>
                                   <Eq>
                                       <FieldRef Name="UserID"/>
                                       <Value Type="Text">Foo.Bar</Value>
                                   </Eq>
                               </Where>
                           </Query>


        ndViewFields.InnerXml = <ViewFields>
                                    <FieldRef Name="Title"/>
                                    <FieldRef Name="FirstName"/>
                                    <FieldRef Name="Company"/>
                                    <FieldRef Name="WorkPhone"/>
                                    <FieldRef Name="HomePhone"/>
                                    <FieldRef Name="Email"/>
                                    <FieldRef Name="UserID"/>
                                </ViewFields>

I have a single item in the list with the optional UserID="John.Doe", and I call GetListItems as follows:

    ''Gets any user from the Sharepoint New Hires list that matches the UserID variable and print to console
            Dim ndListItems As XmlNode =
            sharepointList.GetListItems("New Hires", Nothing, ndQuery, ndViewFields, Nothing, Nothing, Nothing)

Console.WriteLine(ndListItems.OuterXml)

I would expect to not get any results back, as the values in the UserID do not match, but as it turns out, I do get back the list item, which is not what I want to happen. I'm not sure what is going on. Is the query structured correctly? Is there some parameter that I'm not aware of that must be included in GetListItems function?? Here are the results I get back after the function is run.

<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;
<rs:data ItemCount="1">
   <z:row ows_ContentTypeId="0x01060051A3C5B94E00A446B900C3759422E391" ows_Title="Doe" ows_FirstName="John" ows_Email="[email protected]" ows_Company="MyCompany" ows_WorkPhone="987-123-4567" ows_HomePhone="987-123-4567" ows_UserID="John.Doe" ows_ID="6" ows_ContentType="Contact" ows_Modified="2010-08-13 12:58:14" ows_Created="2010-08-13 12:58:14" ows_Author="23;#John Doe" ows_Editor="23;#John Doe" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Doe" ows_LinkTitle="Doe" ows_SelectTitle="6" ows_Order="600.000000000000" ows_GUID="{750F74FC-1CA3-40A2-8237-CD04E0390722}" ows_FileRef="6;#Lists/NewHires/6_.000" ows_FileDirRef="6;#Lists/NewHires" ows_Last_x0020_Modified="6;#2010-08-13 12:58:14" ows_Created_x0020_Date="6;#2010-08-13 12:58:14" ows_FSObjType="6;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="6;#6_.000" ows_UniqueId="6;#{778A7804-ABAA-49DC-9061-DE050DE5F032}" ows_ProgId="6;#" ows_ScopeId="6;#{C084EB37-9260-47CD-A231-AC23477D4856}" ows__EditMenuTableStart="6_.000" ows__EditMenuTableEnd="6" ows_LinkFilenameNoMenu="6_.000" ows_LinkFilename="6_.000" ows_ServerUrl="/Lists/NewHires/6_.000" ows_EncodedAbsUrl="http://sbatsharepoint2/Lists/NewHires/6_.000" ows_BaseName="6_" ows_MetaInfo="6;#" ows__Level="1" ows__IsCurrentVersion="1" />
</rs:data>
</listitems>

UPDATE:

Still haven't had any luck, I had double quotes around field types in the query that I replaced with singe quotes, but that didn't do anything. I also tried replacing the list name with it's GUID, again nothing. I've triple checked all function calls, there parameters and variables. Still not sure what the problem is.

UPDATE2:

Tried testing the query with another field as follows:

ndQuery.InnerXml = <Query>
                               <Where>
                                   <Eq>
                                       <FieldRef Name="Title"/>
                                       <Value Type="Text">Mike</Value>
                                   </Eq>
                               </Where>
                           </Query>

Of course, there is no item in the list with Title="Mike", yet the function still returns all the items.

A: 

You could try this and see if that helps:

    ndQuery.InnerXml = <Query>
                           <Where>
                               <Eq>
                                   <FieldRef Name="ows_UserID"/>
                                   <Value Type="Text">Foo.Bar</Value>
                               </Eq>
                           </Where>
                       </Query>
Floyd Pink
Hi Floyed, just tried that and didn't work, I'm still getting back an item, when I shouldn't be.
kingrichard2005
A: 

Finally, after looking over this MSDN article, turns out I have to pass the query and viewfields as string literals, I observed that in the examples on MSDN, but didn't think the format made a difference, also I had to remove the outer most "<\Query>" tag. The format below is what ended up working for me:

''Search for items in the list with the UserID="Foo.Bar"
        ndQuery.InnerXml = "<Where><Eq><FieldRef Name=""UserID"" />" + "<Value Type=""Text"">Foo.Bar</Value></Eq></Where>"

        ndViewFields.InnerXml = "<FieldRef Name=""Title"" />" + "<FieldRef Name=""FirstName"" />"

What I find strange is that I cannot pass the entire query as a string literal, but have to break it up after the "<\fieldRef>" tag, I'm not sure why that is the case in CAML. Any enlightenment on this is appreciated; at this point, it may as well magic as far as I'm concerned.

kingrichard2005