Filter data from SharePoint List in Code - InfoPath Dev
in

InfoPath Dev

Filter data from SharePoint List in Code

Last post 08-05-2010 08:00 AM by Potemkine. 29 replies.
Page 1 of 2 (30 items) 1 2 Next >
Sort Posts: Previous Next
  • 07-30-2010 11:23 AM

    Filter data from SharePoint List in Code

    Hello,

    I looked for a relatively easy solution to this in the forum but came up empty...

    I am looking for a fairly straight-forward way, via code, to create a connection to a SharePoint List and then filter based on my criteria (InfoPath 2007). I tried:

    • AdoQueryConnection = only works with Access and SQL Server db
    • SharepointListQueryConnection = cannot make heads or tails of it...could not find examples

    Once I have filtered a few tables of data, I will (for lack of a better way of doing it) populate arrays to do JOINS using iteration and an ID field.

    I really miss Access and SQL Server. :) Any thoughts on how I can filter a list in InfoPath code?

    Thanks in advance,

     Pinback

     

  • 07-30-2010 02:02 PM In reply to

    Re: Filter data from SharePoint List in Code

    Hi Pinback,

    Our qRules product does this via code and it is using owssrv queries.

    We do offer a free trial of qRules, it might be faster to use what have already built than writing your own code.

    Ted

  • 07-30-2010 08:54 PM In reply to

    Re: Filter data from SharePoint List in Code

     It's not really difficult:

    -First of all you add your Sharepoint site as a Web reference in VSTA.

    -here some code to do what you want to do:

    sd01 is my web reference

                sd01.Lists lists_ws = new sd01.Lists();

                lists_ws.Url = "http:Mysite/_vti_bin/lists.asmx";


                lists_ws.Credentials = System.Net.CredentialCache.DefaultCredentials;

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

                XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");

                XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
                XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
                ndQuery.InnerXml = Query;
                ndListItems = lists_ws.GetListItems(Mylib, MyView, ndQuery, null, "10000", ndQueryOptions, null);
              

    You have to make a Caml query and put it on the ndquery.Innerxml, I suggest that you use an empty string for the test.

    -

  • 08-02-2010 07:49 AM In reply to

    Re: Filter data from SharePoint List in Code

    Thanks Potemkine,

     I am new to creating web references, so I will have to work on it. I established the reference but did not find a "Lists()" property to declare my object with. I'll look into it further and try to learn more about web references.

     Thanks again!

    Pinback

  • 08-02-2010 08:05 AM In reply to

    Re: Filter data from SharePoint List in Code

     For the web reference did you try :http://<site>/_vti_bin/Lists.asmx ?

    If you didn't, you should try it.


     

  • 08-02-2010 09:16 AM In reply to

    Re: Filter data from SharePoint List in Code

    Thank you again, Potemkine!

    How did you know to look for "_vti_bin/Lists.asmx" and what its purpose is? Do you know a good reference/site/book I should look at?

  • 08-02-2010 09:31 AM In reply to

    Re: Filter data from SharePoint List in Code

     On msdn you have a good example:

     http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx

     

  • 08-03-2010 08:43 AM In reply to

    Re: Filter data from SharePoint List in Code

    Well, I got up to the GetListItems call and received the following error: "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown"

    I could not find more specifics detailing the issue. I'll have to look further into this and see if I can figure it out. Thanks for all of your help!

     

    Pinback

  • 08-03-2010 09:13 AM In reply to

    Re: Filter data from SharePoint List in Code

    Hi pinback, I suggest you to simplify your query :

    ndQuery.InnerXml = "";
    ndListItems = lists_ws.GetListItems(Mylib, null, ndQuery, null, "10000", ndQueryOptions, null);
     

  • 08-03-2010 10:43 AM In reply to

    Re: Filter data from SharePoint List in Code

    Hi Potemkine!

    I'm guessing you are working in C#. I had to convert over to VB. I think I have everything set up the way you did. I wish I knew more about Web References so I could diagnose myself. Thanks again!

                Dim Lst1 As New PROC1.Lists                                     'PROC1 is my Web Reference which shows three files (Lists.disco, Lists.wsdl, and reference.map [reference.vb])
                Dim xlDoc As New System.Xml.XmlDocument
                Dim ndQuery As System.Xml.XmlNode
                Dim ndViewFields As System.Xml.XmlNode
                Dim ndQueryOptions As System.Xml.XmlNode
                Dim ndListItems As System.Xml.XmlNode

                'The URL appears to be set on Lst1 by PROC1
                Lst1.Credentials = System.Net.CredentialCache.DefaultCredentials
                ndQuery = xlDoc.CreateNode(XmlNodeType.Element, "Query", "")
                ndViewFields = xlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "")
                ndQueryOptions = xlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "")
                ndQuery.InnerXml = "" 'Insert caml query here
                ndListItems = Lst1.GetListItems("ProcTraining", Nothing, ndQuery, Nothing, "10000", ndQueryOptions, Nothing)


     

  • 08-03-2010 11:03 AM In reply to

    Re: Filter data from SharePoint List in Code

    Hi,your code seem to be all right, "ProcTraining", is the exact name of your list because web service use the list name,and not the name on the URL, sometime it can be different.

  • 08-03-2010 11:20 AM In reply to

    Re: Filter data from SharePoint List in Code

    Hi,

    It appears to be "ProcTraining". I tried the GUID as well. :(

  • 08-03-2010 11:25 AM In reply to

    Re: Filter data from SharePoint List in Code

    Do you have the good permission to acces to the list ? by default you use your windows default account.

  • 08-03-2010 11:30 AM In reply to

    Re: Filter data from SharePoint List in Code

    To clarify, if you are asking if I have permissions to access the list, then yes I do. My Windows login should have Full Control of the List.

  • 08-03-2010 11:46 AM In reply to

    Re: Filter data from SharePoint List in Code

    Can you send the complete error :

    Under the View Detail, expand exception. See InnerXML under Detail: you will get the exact error. For example, I am getting this error from Microsoft.SharePoint.SoapServer.SoapServerException: "<errorstring xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">There is no Web named \"/sites/test\".</errorstring>".

     

Page 1 of 2 (30 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.