开发者

Help with query for SharePoint (online) Lists.GetListItems

开发者 https://www.devze.com 2023-02-28 02:23 出处:网络
I am trying to get customers with a matching name from a SharePoint list I tried with: XmlDocument doc = new XmlDocument();

I am trying to get customers with a matching name from a SharePoint list I tried with:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<Query><Where><Lt><FieldRef Name=\"CustomerName\"/><Value Type=\"Text\">" + customerName + "</Value></Lt></Where></Query>");
XmlNode listQuery = doc.SelectSingleNode("//Query");

XmlNode n = sharePoint.listsObj.GetListI开发者_如何学编程tems(listName, null, listQuery, null, null, null, null);
nsmgr = new XmlNamespaceManager(n.OwnerDocument.NameTable);
nsmgr.AddNamespace("z", "#RowsetSchema");
nsmgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
XmlNodeList itemNodeList = n.SelectNodes("rs:data/z:row", nsmgr);

But in itemNodeList I get a customer with a name that is not similar at all to the parameter (customerName) I use in the query.

If I don't pass on the query I get all customers from the list.

Any ideas?

Thanks in advance.


If you want to get names that match exactly then use the Eq tag

For example from

  • Smith
  • Smith-Jones
  • Jones

the following

<Query><Where><Eq><FieldRef Name="CustomerName"/><Value Type="Text">Smith</Value></Eq></Where></Query>

would return

  • Smith

If you want to return names that contain the string then use the Contains tag

<Query><Where><Contains><FieldRef Name="CustomerName"/><Value Type="Text">Smith</Value></Contains></Where></Query>

would return

  • Smith-Jones
  • Jones

Have a look at the U2U CAML Builder

http://www.u2u.net/res/Tools/CamlQueryBuilder.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消