Retrieve document ID from SharePoint 2010 via SOAP Web Services – GetListItems
- August 30th, 2011
- Posted in Microsoft / CRM / SharePoint / SSRS
- Write comment
Get a specific item from a SharePoint 2010 library using GetListItems.
// Build the CAML Query System.Text.StringBuilder oSb = new System.Text.StringBuilder(); oSb.Append(" <Query>"); oSb.Append(" <Where>"); oSb.Append(" <Eq>"); oSb.Append(" <FieldRef Name=\"FileLeafRef\" />"); oSb.Append(" <Value Type=\"Text\">" + fileName +"</Value>"); oSb.Append(" </Eq>"); oSb.Append(" </Where>"); oSb.Append(" </Query>"); string sResult = oSb.ToString(); XmlDocument CAMLqueryXML = new XmlDocument(); CAMLqueryXML.LoadXml(sResult); //Build the CAML Query Options oSb.Clear(); // Clear the string builder oSb.Append(" <QueryOptions>"); oSb.Append(" <Folder>" + libraryName + "/</Folder> />"); oSb.Append(" </QueryOptions>"); string CAMLqueryOptions = oSb.ToString(); XmlDocument CAMLqueryOptionsXML = new XmlDocument(); CAMLqueryOptionsXML.LoadXml(CAMLqueryOptions); // Execute GetListItems XmlNode queryResults = lists.GetListItems(libraryName, null, CAMLqueryXML, null, null, CAMLqueryOptionsXML, null);
This is not valid. GetListItems requires System.Xml.Linq.XElement for the query. XMLDocument is not valid.
Hi Clem,
You don’t need XElement for GetListItems. Here’s an MSDN example of using GetListItems and XMLDocument. http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12).aspx
Thanks,
Ryan
You are absolutely right. I was mistaken. I added the web service as a service reference instead of a web reference. My mistake. Thanks for the example. Service reference provides different methods and objects.