locked
Argument 3: cannot convert from 'System.Xml.XmlElement' to 'System.Xml.Linq.XElement" How can i solve this problem? RRS feed

  • Question

  • Here is my code :

    ListsSoapClient client = new ListsSoapClient();
                client.ClientCredentials.Windows.ClientCredential.Domain = "********";
                client.ClientCredentials.Windows.ClientCredential.UserName = "*********";
                client.ClientCredentials.Windows.ClientCredential.Password = "**********";
    
                try
                {
                    /* Assign values to pass the GetListItems method*/
                    string listName = "************";
                    string viewName = "***************";
                    string rowLimit = "100";
    
                    // Instantiate an XmlDocument object
                    XmlDocument xmlDoc = new XmlDocument();
                    XmlElement query = xmlDoc.CreateElement("Query");
                    XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
                    XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
    
                    /*Use CAML query*/
                    query.InnerText = "<Where><Gt><FieldRef Name=\"ID\" />" +
                    "<Value Type=\"Counter\">0</Value></Gt></Where>";
                    viewFields.InnerText = "<FieldRef Name=\"Title\" />";
                    queryOptions.InnerText = "";
    
                    
    
                    XNode nodes = client.GetListItems(listName, viewName, query, viewFields, rowLimit, null, null);
                    
                }
                catch (Exception)
                {
    
                    throw;
                }


    19karabo91

    Friday, November 15, 2013 8:43 AM

Answers

  • From the error, it looks like your client.GetlistItems method expects the query to be a System.Xml.Linq.XElement rather than a System.Xml.XmlElement. To fix this, define and set up query as the right class (XElement)

    --Rob

    • Marked as answer by Anne Jing Tuesday, November 26, 2013 7:56 AM
    Saturday, November 16, 2013 2:10 AM
    Moderator

All replies

  • From the error, it looks like your client.GetlistItems method expects the query to be a System.Xml.Linq.XElement rather than a System.Xml.XmlElement. To fix this, define and set up query as the right class (XElement)

    --Rob

    • Marked as answer by Anne Jing Tuesday, November 26, 2013 7:56 AM
    Saturday, November 16, 2013 2:10 AM
    Moderator
  • I want all the records of the list and thus, am not specifying any query, simply passing:

    query.InnerText = "";

    Still I am getting the same error!

    Monday, February 24, 2014 10:25 AM