How to access SharePoint information using code that executes on the SharePoint server itself. The rest of this chapter focuses on methods of accessing SharePoint data from remote locations, whether that means accessing SharePoint using HTTP, a client application such as Silver light, or web service.
SharePoint 2010 provides a way of accessing list data using a Representational State Transfer (REST) interface. (Interfaces utilizing the REST interface are referred to as RESTful .) The RESTful interface provides a simple way for external applications to access and modify SharePoint data.
It makes it possible to retrieve an XML representation of list data by simply supplying a URL. It ’ s possible to carry out basic CRUD (create, read, update, and delete) operations using the REST interface, by using the HTTP operations of POST, GET, PUT, and DELETE. By passing in various parameters with your URLs, it ’ s possible to a filter and sort the data that you get back.
For your RESTful service to work, you must have installed the ADO.NET Data Services Update for .NET Framework 3.5 SP1.
You can supply ADO.NET Data Services with a SharePoint data source by passing it a RESTful URL from SharePoint. To learn more about this, read the article “ Query SharePoint Foundation with ADO.NET Data Services ” at http://msdn.microsoft.com/en - us/library/ee535480.aspx
To access the RESTful service, you ’ ll need to reference the following URL: /_vti_bin/ListData.svc.This URL should be appended to whichever site you are querying. For instance, if you want to retrieve list data from the accounting department ’ s site in your intranet, you would use a URL of http://intranet/sites/accounting/_vti_bin/ListData.svc.
You can see what kinds of results get returned by browsing to the list data service URL of the SharePoint site in your browser. If the results conform to an RSS standard, your browser may interpret the results as an RSS feed for you to subscribe to, which means it won ’ t display straight XML. When querying a particular list item, your browser might not be able to interpret the results as a feed and might give you an error.
You can get every list item out of a particular list in the site by appending the name of the list to the end of the URL. For example, to get all the documents from the Documents library in your accounting site, you would use a URL of:
You can retrieve one particular list item from a list by passing in the ID of that list item after the list name, like this:
You can also find out the column value for one particular list item by passing the column name after the item number like this:
You can sort your results by using the parameter $orderby and passing in the name of the column you would like to sort your results by. For instance, if you want to sort your documents by title, you would use a URL of:
You can even execute a CAML query on your list by passing in a $filter parameter. For instance,
if you wanted to retrieve a document whose title was My Document, you could use a URL like:
http://intranet/sites/accounting/_vti_bin/ListData.svc/Documents?$filter=Title eq ‘ My Document ’
Although it ’ s unconventional to have spaces in your URL, it ’ s permitted when using the RESTful service.
To read more about the RESTful service, visit the SDK article online:
http://msdn.microsoft.com/en - us/library/ff521587.aspx