Results 1 to 4 of 4

Thread: [RESOLVED] help with GetListItems for Sharepoint List Services

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] help with GetListItems for Sharepoint List Services

    will anybody help me with this..I copied the code below from Microsoft Windows Sharepoint Services SDK but it just wont work everytime i execute that code. can anybody body please tell me whats wrong or is there something i missed in that code..by the way the error in the code below happens in this line

    Code:
    System.Xml.XmlNode nodeListItems = listService.GetListItems(listName,viewName,query,viewFields,rowLimit,queryOptions);
    Code:
                // Declare and initialize a variable for the Lists Web Service.
                List_Service.Lists listService = new List_Service.Lists();
    
                /* Authenticate the current user by passing their default 
                credentials to the Web Service from the system credential cache.*/
                listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
                // Set the Url property of the service for the path to a subsite.
                listService.Url = "http://sharepoint/_vti_bin/Lists.asmx";
    
                // Instantiate an XmlDocument object
                System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
    
                /* Assign values to the string parameters of the GetListItems method, 
                using GUIDs for the listName and viewName variables*/
                string listName = "{17991794-81BB-494F-9910-CFBF1093A7CF}";
                string viewName = "{7137FFF8-48FF-4C69-8C76-0E3BBD1EA7F9}";
                string rowLimit = "150";
    
                /*Use the CreateElement method of the document object to create elements 
                for the parameters that use XML*/
                System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
                System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
                System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
    
                /*To specify values for the parameter elements (optional), assign CAML fragments
                to the InnerXml property of each element*/
                query.InnerXml = "<Where><Gt><FieldRef Name=\"ID\" />" +
                "<Value Type=\"Counter\">3</Value></Gt></Where>";
                viewFields.InnerXml = "<FieldRef Name=\"Title\" />";
                queryOptions.InnerXml = "";
    
                /* Declare an XmlNode object and initialize it with the XML response from 
                the GetListItems method.*/
                System.Xml.XmlNode nodeListItems = listService.GetListItems(listName,viewName,query,viewFields,rowLimit,queryOptions);
                
                // Loop through each node in the XML response and display each item.
                foreach (System.Xml.XmlNode listItem in nodeListItems)
                {
                    label1.Text += listItem.OuterXml;
                }
    Error details...

    System.Web.Services.Protocols.SoapException was unhandled
    Message="Exception of type Microsoft.SharePoint.SoapServer.SoapServerException was thrown."
    Source="System.Web.Services"
    Actor=""
    Lang=""
    Node=""
    Role=""
    StackTrace:
    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
    at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
    at WindowsApplication1.List_Service.Lists.GetListItems(String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions) in C:\Documents and Settings\absalvamante\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\Web References\List_Service\Reference.cs:line 484
    at WindowsApplication1.frmindex.button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\absalvamante\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\frmindex.cs:line 778
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(Form mainForm)
    at WindowsApplication1.Program.Main() in C:\Documents and Settings\absalvamante\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\Program.cs:line 17
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()

  2. #2

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: help with GetListItems for Sharepoint List Services

    i've already solved the problem...there is an error from query option. The column doesn't exist in my Events list.

  3. #3
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: [RESOLVED] help with GetListItems for Sharepoint List Services

    I am running into the same problem. How did you fix this?

  4. #4
    New Member
    Join Date
    Dec 2008
    Posts
    1

    Re: [RESOLVED] help with GetListItems for Sharepoint List Services

    I had the same problem. for listName and viewName, put GUID for each. i found the GUID in the sharepoint page URL in the query string. QueryOptions must be updated to include several fields, not left blank.

    Web_Reference_Folder.Lists listService = new Web_Reference_Folder.Lists();
    listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

    XmlDocument xmlDoc = new System.Xml.XmlDocument();

    string listName = "{7C344558-7D23-463F-842D-B53020780C52}";
    string viewName = "{98D0FEE7-A871-4353-81D8-676027C6B885}";
    string rowLimit = "150";

    XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query","");
    XmlNode ndViewFields =
    xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields","");
    XmlNode ndQueryOptions =
    xmlDoc.CreateNode(XmlNodeType.Element,"QueryOptions","");

    ndQueryOptions.InnerXml =
    "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" +
    "<DateInUtc>TRUE</DateInUtc>";
    ndViewFields.InnerXml = "<FieldRef Name='Field1' />
    <FieldRef Name='Field2'/>";
    ndQuery.InnerXml = "<Where><And><Gt><FieldRef Name='Field1'/>" +
    "<Value Type='Number'>5000</Value></Gt><Gt><FieldRef Name='Field2'/>" +
    "<Value Type=
    'DateTime'>2003-07-03T00:00:00</Value></Gt></And></Where>";
    try
    {
    XmlNode ndListItems =
    listService.GetListItems(listName, viewName, ndQuery,
    ndViewFields, rowLimit, ndQueryOptions, null);
    TextBox1.Text = ndListItems.OuterXml;
    }

    catch (System.Web.Services.Protocols.SoapException ex)
    {
    TextBox1.Text = "Message:\n" + ex.Message + "\nDetail:\n" +
    ex.Detail.InnerText +
    "\nStackTrace:\n" + ex.StackTrace;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width