Lists.asmx, GetListItems dhe dosjet

Unë kam qenë duke bërë disa kërkime për dikë sot rreth shërbimit të internetit list.asmx ofruara si pjesë e SharePoint 2010 (dhe më herët).  Ajo ishte në gjendje për të marrë sendet listë në dosjen rrënjë (duke përfshirë edhe emrat e sub-folders), por nuk mund të merrni artikuj në sub-folders.  I did some looking around on the internets and it’s a surprisingly common question.  Ende, I couldn’t get a good answer to the simple question, “if I know the folder, how do I get the items in the folder?"  To be honest, I didn’t try all that hard since I’ve wanted to figure this one out on my own for a while buzëqeshje.

To set this up, I created a site named “Blogging Scenarios” and a custom list named “Custom List with Sub Folders”.  I then created folders named:

  • Year 2005
  • Year 2006
  • Year 2007

I added a few items to the folder “Year 2006”.  Kjo është ajo që duket si:

image

My friend isn’t writing C# code but rather using Java, so the SOAP envelope was what she really needed.  To get that, I wrote a bit of jQuery and then used fiddler to get the actual HTTP conversation.

Here’s the relevant jQuery (I copied the code down below if you want to copy/paste):

image

They first key is to include both a <queryOptions> dhe <QueryOptions> node.  The second key is that the <Folder> node is a URL to which the client has access.

There may be other ways to get this, but this worked well for me when using jQuery.

Here is the SOAP envelope for the above:

<soapenv:Envelope xmlns:soapenv=’http://schemas.xmlsoap.org / sapun / Zarfi /’>                
  <soapenv:Trup>
    <GetListItems xmlns=’
http://schemas.microsoft.com / SharePoint / sapun /’>
      <listName>Custom List with Sub Folders</listName>
      <viewFields>  
        <ViewFields>
          <FieldRef Name=’Title’ />
          <FieldRef Name=’EncodedAbsUrl’ />
        </ViewFields>
      </viewFields>
      <queryOptions>
        <QueryOptions>
          <Folder>
http://demoserver1/Blogging Scenarios/lists/Custom List with Sub Folders/Year 2006</Folder>
        </QueryOptions>
      </queryOptions>
   
</GetListItems>
  </soapenv:Trup>
</soapenv:Zarf>

A lot of examples and discussion around this led me to believe that all I need was <QueryOptions> and specify a folder name.  Për mua, I need to both wrap it inside <queryOptions> as well as specify a fully qualified URL for the <Folder> node.

Here’s the jQuery AJAX setup:

$(dokument).gati(funksion() {
       var soapEnv =
           "<soapenv:Envelope xmlns:soapenv=’http://schemas.xmlsoap.org / sapun / Zarfi /’> \
               <soapenv:Trup> \
                    <GetListItems xmlns=’http://schemas.microsoft.com / SharePoint / sapun /’> \
                       <listName>Custom List with Sub Folders</listName> \
                       <viewFields> \
                           <ViewFields> \
                              <FieldRef Name=’Title’ /> \
                              <FieldRef Name=’EncodedAbsUrl’ /> \
                          </ViewFields> \
                       </viewFields> \
                       <queryOptions> \
                         <QueryOptions> \
                           <Folder>http://demoserver1/Blogging Scenarios/lists/Custom List with Sub Folders/Year 2006</Folder> \
                         </QueryOptions> \
                       </queryOptions> \
                   </GetListItems> \
               </soapenv:Trup> \
           </soapenv:Zarf>";

</fund>

Abonohen në blogun tim.

Atëherë ejani pas meje në Twitter në http://www.twitter.com/pagalvin

6 mendime mbi "Lists.asmx, GetListItems dhe dosjet

  1. Daniel

    Hi

    I am trying to display the documents under a specific folder using a SPD 2010 DataSource GetListItems

    Once I connect to to my web service and enter the guid for the document library
    I can modify the QueryOptions and enter the following piece of CAML
    Compliance Training\CompanyX.

    Only this does not return any results – removing the QueryOptions parameter returns all the documents in the root document library….

    Am I looking at passing some sort of view parameter and include the view guid.

  2. Bob Bolton

    Ok, looks like it stripped out the xml… just replace the pound signs below with chevrons.

    #queryOptions#
    #QueryOptions#
    #ViewAttributes Scope=’RecursiveAll’/#
    #/QueryOptions#
    #/queryOptions#

  3. Doug

    Thanks a bunch for this post, Paul. I’ve been trying to consume GetListItems via ColdFusion cfhttp, and couldn’t get the envelope right. Eventually came across this post, and your example worked flawlessly. Thanks again.

  4. Doug

    Btw – do you know of a resource that lists all the proper soap envelopes? The one for GetList Items published on microsoft.com doesn’t match your here…

Lini një Përgjigju

Adresa juaj e emailit nuk do të publikohet. Fusha e kërkuar janë shënuar *