为什么 <ViewFields>标准被 SharePoint 列表服务的 GetListItems 方法忽略 [英] Why does <ViewFields> criteria get ignored by the SharePoint List Service's GetListItems Method

查看:11
本文介绍了为什么 <ViewFields>标准被 SharePoint 列表服务的 GetListItems 方法忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我在我的共享点列表服务的 GetListItems 查询中指定了一个 ViewFields 元素,但所有字段都会返回.以下代码构建请求:

Although I specify a ViewFields element in my sharepoint list service's GetListItems query, all fields are returned. The following code builds the request:

XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode query = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode viewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode queryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");    

... set query ...

viewFields.InnerXml = "<FieldRef Name='LinkFilename' /><FieldRef Name='FileDirRef' /><FieldRef Name='FileLeafRef' />";            

queryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc><Folder>Resource Management Tools</Folder><ViewAttributes Scope='Recursive' />";

XmlNode xmlNode = SharePointListWebService.GetListItems(
_listServiceConfigurationSettings.ListName,
                                string.Empty,
                                query,
                                viewFields,
                                null,
                                queryOptions,
                                null);

根据 fiddler 的说法,这会导致以下肥皂信封被发布到列表服务:

According to fiddler, this results in the following soap envelope being posted to the list service:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">    
      <listName>Shared Documents</listName>
      <viewName />
      <query>
        <Query xmlns="">
          <Where>
            <And>
              <Contains>
                <FieldRef Name="FileLeafRef" />
                <Value Type="Text">.xls</Value>
              </Contains>
              <Geq>
                <FieldRef Name="Modified"
                IncludeTimeValue="True" />
                <Value Type="DateTime">2010-05-10T11:53:32Z</Value>
              </Geq>
            </And>
          </Where>
          <OrderBy>
            <FieldRef Name="FileDirRef" />
          </OrderBy>
        </Query>
      </query>
      <viewFields>
        <ViewFields xmlns="">
          <FieldRef Name="LinkFilename" />
          <FieldRef Name="FileDirRef" />
          <FieldRef Name="FileLeafRef" />
        </ViewFields>
      </viewFields>
      <queryOptions>
        <QueryOptions xmlns="">
          <IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>
          <DateInUtc>TRUE</DateInUtc>
          <Folder>Resource Management Tools</Folder>
          <ViewAttributes Scope="Recursive" />
        </QueryOptions>
      </queryOptions>
    </GetListItems>
  </soap:Body>
</soap:Envelope>

以及从服务返回的以下soap响应:

and the following soap response being returned from the service:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <GetListItemsResult>
        <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'>
          <rs:data ItemCount="19">
            <z:row ows_LinkFilename='[SENSITIVE DATA].xls'
            ows_FileDirRef='278;#sites[SENSITIVE DATA]'
            ows_FileLeafRef='278;#[SENSITIVE DATA].xls'
            ows_MetaInfo='278;#Subject:SW| vti_parserversion:SR|12.0.0.6421 ContentTypeId:SW|0x0101006C2E647253A1074FB6079F08E5F2A395 _Author:SW|[SENSITIVE DATA] _Category:SW| vti_author:SR|[SENSITIVE DATA] _Comments:SW| vti_approvallevel:SR| vti_categories:VW| vti_cachedcustomprops:VX|vti_approvallevel vti_categories Subject vti_assignedto Keywords _Author _Category _Comments vti_assignedto:SR| Keywords:SW| vti_modifiedby:SR|[SENSITIVE DATA]'
            ows__ModerationStatus='0' ows__Level='1'
            ows_Last_x0020_Modified='278;#2010-06-29T18:55:38Z'
            ows_ID='278' ows_owshiddenversion='53'
            ows_UniqueId='278;#{0E51B2B1-89A7-4895-8ECC-0FE7D420470C}'
            ows_FSObjType='278;#0'
            ows_Created_x0020_Date='278;#2009-03-09T16:06:41Z'
            ows_ProgId='278;#' ows_Modified='2010-06-29T18:55:37Z'
            ows_FileRef='278;#sites[SENSITIVE DATA].xls'
            ows_DocIcon='xls'
            ows_Editor='262;#[SENSITIVE DATA]' />            
          </rs:data>
        </listitems>
      </GetListItemsResult>
    </GetListItemsResponse>
  </soap:Body>
</soap:Envelope>

请注意 z:row 元素包含的字段比我在 ViewFields 条件中指定的多.我还在查询选项中将 IncludeMandatoryColumns 设置为 false.是我做错了什么,还是我不明白 ViewFields 的真正工作原理,因为我认为它会限制字段,即 SharePoint 列表服务返回的 z:row 属性.

Notice the z:row element has more fields included than I specified in my ViewFields criteria. I also set IncludeMandatoryColumns to false in my query options. Did I do something wrong or do I not understand how ViewFields really works as I thought it would limit the fields i.e. z:row attributes returned by the SharePoint list service.

推荐答案

我也一直在为这个问题苦苦挣扎.今晚我找到了一个似乎对我有用的解决方案......希望它对其他人也有帮助.

I've been struggling with this issue, too. Tonight I found a solution that seems to work for me...hopefully it's helpful for others, as well.

您的 viewFields 节点的结构很好...

The structure of your viewFields node is fine...

   <viewFields>
    <ViewFields xmlns="">
      <FieldRef Name="LinkFilename" />
      <FieldRef Name="FileDirRef" />
      <FieldRef Name="FileLeafRef" />
    </ViewFields>
  </viewFields>

问题很可能是您的字段名称.显然,您必须使用内部名称而不是显示名称.一个快速&确定内部名称的简单方法是转到列表的列表设置"页面,并将鼠标悬停在列表中的每一列上.浏览器的状态栏会显示类似这样的网址..

The problem is likely your field names. Apparently you have to use the internal names rather than the display names. One quick & easy way to determine the internal names is to go to the List Settings page for your list and hover over each column in the list. The browser's status bar will show a URL similar to this..

http://YOUR_SITE/_layouts/FldEdit.aspx?List=%7B12345678%2D1234%2D1234%2D1234%2D123456789012%7D&Field=INTERNAL_FIELD_NAME

对于您要从 GetListItems() 服务返回的每个字段,使用此处显示的内部字段名称.例如,

Use the internal field name shown there for each of the fields you want to return from the GetListItems() service. For example,

<FieldRef Name="LinkFilename" />

....可能需要写成...

....might need to be written as...

<FieldRef Name="Link_x0020_Filename" />

至少这是为我解决问题所需要的.希望有帮助!

At least that's what it took to solve the problem for me. Hope that helps!

这篇关于为什么 &lt;ViewFields&gt;标准被 SharePoint 列表服务的 GetListItems 方法忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆