0

How to Display SharePoint list item by selecting id of the item by using list web services (lists.asmx).

1
  • using C# client object model? Commented Jul 10, 2014 at 9:00

1 Answer 1

0

You can use below code.

Change the ID in CAML query according to your needs. I am using get me item whose ID=1

public void getListData()
        {
            WS_Lists.Lists myservice = new WS_Lists.Lists();
            myservice.Credentials = System.Net.CredentialCache.DefaultCredentials;
            myservice.Url = "http://site/_vti_bin/Lists.asmx";
            try
            {
                /* Assign values to pass the GetListItems method*/
                string listName = "ListName";
                string viewName = "ViewName";
                string rowLimit = "1";

                // Instantiate an XmlDocument object
                System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
                System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
                System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");

                /*Use CAML query*/
                query.InnerXml = "<Where><eq><FieldRef Name=\"ID\" />" +
                "<Value Type=\"Counter\">1</Value></eq></Where>";
                viewFields.InnerXml = "<FieldRef Name=\"Title\" />";
                queryOptions.InnerXml = "";

                System.Xml.XmlNode nodes = myservice.GetListItems(listName, viewName, query, viewFields, rowLimit, null, null);

                foreach (System.Xml.XmlNode node in nodes)
                {
                    if (node.Name == "rs:data")
                    {
                        for (int i = 0; i < node.ChildNodes.Count; i++)
                        {
                            if (node.ChildNodes[i].Name == "z:row")
                            {
                                Response.Write(node.ChildNodes[i].Attributes["ows_Title"].Value + "</br>");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
1
  • Please mark it as answer if it's working. And thanks is nothing without an UpVote :) Commented Jul 10, 2014 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.