Domanda

I am trying to get all list items of a sharepoint list using WebServices into a Windows 7 gadget, but I am not really sure how I can do that,

I find this code on google without any explanation, So I dont know how I will get the data of list using this code and then display in a Windows Gadget.

Can anyone guide me to the right direction please ?

Gadget.xml is

    <?xml version="1.0" encoding="utf-8" ?>
<gadget>
  <name>HelloGadget</name>
  <version>1.0.0.0</version>
  <description>Hello World Gadget.</description>
  <hosts>
    <host name="sidebar">
      <base type="HTML" apiVersion="1.0.0" src="first.html" />
      <permissions>Full</permissions>
      <platform minPlatformVersion="1.0" />
    </host>
  </hosts>
</gadget>

first.html is

    <html>
<script>
//----------------- resizes the gadget display surface
function DoInit() {
    document.body.style.width = 90;
    document.body.style.height= 55;
    document.body.style.margin=0;
}

    $(document).ready(function() 
{
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> 
            <soapenv:Body> 
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> 
                    <listName>ListName</listName> 
                    <viewFields> 
                        <ViewFields> 
                           <FieldRef Name='Title' /> 
                       </ViewFields> 
                    </viewFields> 
                </GetListItems> 
            </soapenv:Body> 
        </soapenv:Envelope>";

    $.ajax({
        url: "http://my_site/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset="utf-8""
    });
});

function processResult(xData, status) {
    $(xData.responseXML).find("z\:row").each(function() {
        alert($(this).attr("ows_Title"));
    });
}

</script>
<body onload="DoInit();">
<table border="5"><tr><td><center><i>Hello World!</i></center></td></tr></table>
<div id = "clickit"> <button type="button" onclick="" >Click Me!</button> </div>
</body>
</html>

Cheers

È stato utile?

Soluzione

We are all familiar with SQL. There is a new jQuery library called SPSQL. This is really cool because you can query SharePoint using SQL syntax. Just add the appropriate libraries and you are on your way. See the example below and article here.

To get items, just do the following:

var result = SPSql.parseSQL('SELECT MyList.Field FROM MyList WHERE MyList.ID > 10 ORDER BY  MyList.ID DESC');

Now it is possible to process all result rows:

for (var row = 0; row < result.length; row++) {
   for (var column in result[row])
      alert( column + ": " + result[row][column] );
 }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top