【发布时间】:2012-03-27 12:52:50
【问题描述】:
SharePoint Web Service 有一个带有以下签名的方法:
public System.Xml.XmlNode GetListItems(string listName, string viewName, System.Xml.XmlNode query, System.Xml.XmlNode viewFields, string rowLimit, System.Xml.XmlNode queryOptions, string webID) {
object[] results = this.Invoke("GetListItems", new object[] {
listName,
viewName,
query,
viewFields,
rowLimit,
queryOptions,
webID});
return ((System.Xml.XmlNode)(results[0]));
}
我只想返回列表中的“ID”和“Title”列,例如“ProductNames”而不是返回所有列。
如何使用这个webmethod来实现只返回某些列?
我正在使用以下方法返回所有列:
public XmlNode GetListItems(string listName, XmlElement camlQuery)
{
sp.Lists listService = this.getSPListService();
XmlDocument xmlDoc = new XmlDocument();
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
XmlElement foldersEl = xmlDoc.CreateElement("Folder");
if (camlQuery == null) // override default view filters
{
camlQuery = xmlDoc.CreateElement("Query");
camlQuery.InnerXml = "<Where><Gt><FieldRef Name='ID'/><Value Type='Number'>0</Value></Gt></Where>";
}
queryOptions.AppendChild(foldersEl);
return listService.GetListItems(listName, null, camlQuery, ndViewFields, int.MaxValue.ToString(), queryOptions, null);
}
所以,现在我想写一个新方法,比如:
public XmlNode GetListItems(string listName, XmlElement camlQueryForFilteringRows, bool includeAllColumns, string[] columnNamesToInclude)
{
}
并用
调用它var listItems = GetListItems("ProductNames", null, new [] {"ID", "Title"});
我尝试将以下结构添加到 ViewFields 变量中,但它仍然返回所有列:
<ViewFields>
<FieldRef Name="ID" />
<FieldRef Name="Title" />
</ViewFields>
谢谢,
【问题讨论】:
-
我相信这是一个错误。但是,它确实会首先引入您在 ViewFields 中指定的字段。因此,您可能会采取一种解决方法,只返回前 X 列,其中 X 是指定的 ViewField 数。
标签: c# web-services list sharepoint caml