Wednesday, June 29, 2011

Read SharePoint 2010 List item using Web Service

 

This sample uses the GetList operation of the Lists.asmx service to retrieve the configuration of the target list to query. It then loads the items of the list by using the GetListItems operation,providing a default query over the default view of the list.

String targetListName = "News";
String baseUrl = "http://local/_vti_bin/";
Lists wsLists = new Lists();
wsLists.Url = baseUrl + "Lists.asmx";
wsLists.Credentials = System.Net.CredentialCache.DefaultCredentials;
XElement listMetadata = XElement.Load(new XmlNodeReader(wsLists.GetList(targetListName)));
Guid targetListId = new Guid(listMetadata.Attribute("ID").Value);
XmlNode listItemsXmlNode = wsLists.GetListItems( targetListId.ToString(), // ID of the target list
String.Empty, // ID of the view or String.Empty for default view
null, // CAML query or null
null, // ViewFields or null
"200", // RowLimit as a string
null, // Query options
null // ID of the web site or null for root website
);

XElement listItemsXml = XElement.Load(new XmlNodeReader(listItemsXmlNode));
var xmlItems = from x in listItemsXml.Descendants("{#RowsetSchema}row")
select x;
foreach (XElement xmlItem in xmlItems) {
Console.WriteLine("{0} - {1}",
xmlItem.Attribute("ows_ID").Value,
xmlItem.Attribute("ows_Title").Value);
}

 

Both of the operations we invoked (Lists.GetList and SiteData.GetListItems) return a result in the form of XML; in fact, we use classes of LINQ to XML to read and parse them. While working with SharePoint SOAP services, you will need to be accustomed to managing different kinds of results, because it is common for XML results to be presented in various ways (XmlNode, String, arrays of custom types, and so on).

Tuesday, June 21, 2011

Main OOTB Services Published by SharePoint 2010

 

Alerts.asmx

Allows listing and deleting alerts subscriptions for users.


Authentication.asmx

Provides an operation for logging on to a SharePoint site that uses FBA. The Login operation returns a cookie that should be used in all subsequent calls to other services.


Lists.asmx

Provides operations to work with lists, content-types, list items, and files. For example, this service offers operations to check-in and check-out a file in a document library, or to query list data using CAML queries.


SiteData.asmx

Allows reading sites, webs, lists, and items. SiteData.asmx targets external search engines willing to crawl contents of a SharePoint site.


Sites.asmx

Allows creating, deleting, reading, exporting, and importing of SharePoint websites.


Webs.asmx

Provides operations to manage content-types, site columns, and features of a SharePoint website


Search.asmx

A service that allows querying the search engine of SharePoint Server.