locked
Get other user's tasks by Webservice List GetListItems RRS feed

  • Question

  • how to get tasks assign to a user and unfinished tasks by webservice?

     

    thanks in advance


    Thursday, April 7, 2011 5:54 AM

Answers

  • Hi,

    Please try this console application to get all user's uncompleted tasks:

    using System.Xml;
    using System;
    
    namespace GetUncompletedTasks
    {
      class Program
      {
        static void Main(string[] args)
        {
          ListConsoleApplication.ListWebReference.Lists listService = new ListConsoleApplication.ListWebReference.Lists();
          listService.Credentials = new System.Net.NetworkCredential("Administrator", "12345");
          XmlDocument xmlDoc = new System.Xml.XmlDocument();
          string userName = @"HERCULES\dmitry.kaloshin";
    
          XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
          ndQuery.InnerXml = @"<Where>
                      <And>
                        <Eq>
                         <FieldRef Name='AssignedTo' />
                         <Value Type='User'>" + userName + @"</Value>
                        </Eq>
                        <Neq>
                         <FieldRef Name='Status' />
                         <Value Type='Text'>Completed</Value>
                        </Neq>
                      </And>
                     </Where>";                
          XmlNode ndListItems = listService.GetListItems("Tasks", null, ndQuery, null, null, null, null);
          if (ndListItems != null)
          {
            foreach (XmlNode node in ndListItems.ChildNodes)
            {
              if (node.Name == "rs:data")
              {
                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                  if (node.ChildNodes[i].Name == "z:row")
                  {
                    string title = node.ChildNodes[i].Attributes["ows_Title"].Value;
                    Console.WriteLine("Task " + title + " is uncompleted by " + userName);
                  }
                }
              }
            }
          }
        }
      }
    }
    

    If you wish to get a list of all tasks you should remove

    <Neq>
    <FieldRef Name='Status' />
    <Value Type='Text'>Completed</Value>
    </Neq>
    
    
    from ndQuery.


    Dmitry

    Lightning Tools Check out our SharePoint tools and web parts
    • Marked as answer by ayya Thursday, April 7, 2011 1:32 PM
    Thursday, April 7, 2011 10:07 AM