2

我正在使用 CAML 通过 Web 服务查询 SharePoint 列表并输出到 C#/ASP.Net 中的 GridView。我遇到的问题是显示的列多于我在查询的“ViewFields”部分中指定的列(例如,如下所示)。

viewFields.InnerXml = "<ViewFields>" +
                      "<FieldRef Name="Col1" />" +
                      "<FieldRef Name="Col2" />" +
                      "<FieldRef Name="Col3" />" +
                      "<FieldRef Name="Col4" />" +
                      "</ViewFields>";

我尝试在“QueryOptions”中设置为 false。

任何人都可以为这个问题提供任何解决方案,以便只返回指定的列吗?

4

1 回答 1

0

This is to help people who are looking for an answer to this question, the solution we found most effective:

We took the node idea from here: How to Return Only Certain Columns of a List When using the SharePoint Web Service?

Then we went through the process of extract the fields that we want into a datatable. Firstly we create an appropriate amount of columns to fields. Then going through the child nodes to extract all the row data. Doing this for each of the fields that we have requested.

  var myData = new DataTable();

        foreach (string field in fields)
        {
            myData.Columns.Add(field);
        }

        foreach (XmlNode node in nodeListItems)
        {
            // rs = RowSet
            if (node.Name == "rs:data")
            {
                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                    if (node.ChildNodes[i].Name == "z:row")
                    {
                        DataRow row = myData.NewRow();
                        foreach (string field in fields)
                        {
                            var xmlAttributeCollection = node.ChildNodes[i].Attributes;
                            if (xmlAttributeCollection != null)
                                row[field] = xmlAttributeCollection["ows_" + field].Value;
                        }
                        myData.Rows.Add(row);
                    }
                }
            }
        }
        return myData;
于 2013-08-15T09:20:32.960 回答