How can I get the Value from a SharePoint List? - InfoPath Dev
in

InfoPath Dev

How can I get the Value from a SharePoint List?

Last post 04-17-2007 11:35 AM by Shiva. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 02-05-2006 10:24 PM

    • v-luchen
    • Not Ranked
    • Joined on 01-20-2006
    • China
    • Posts 6

    How can I get the Value from a SharePoint List?

    Hi all
    I want to get the data from a SharePoint List.Is there any web service from SharePoint can do the job?
    For example, I want to get the data from a SharePoint List,and then put them into a datatable(coding by C#)

    How can I do this?
  • 02-06-2006 02:59 AM In reply to

    Re: How can I get the Value from a SharePoint List?

    Hi

    depending on what exactly you want to achieve you can approach this in two ways:

    if you just want to retrieve meta data from lists (eg tasks or similar) to populate a dropdown in a form, you can add the list as a secondary data source ( tools > data connections > add > recieve data > sharepoint library or list).

    These data can then be used either in the gui or programmatically using XDocument.DataAdapters("YourListName").DOM.xml (DataObject of type SharepointListAdapter )

    If this isnt enough (for example if you need to access the documents in a list as binary arrays) you can use the standard sharepoint Lists web service methods. The one you need is most likely GetListItems.http://yourPortal/yoursubarea/_vti_bin/lists.asmx <- notice that the vti_bin must be called from the site or area where the list is located!

    more info:
    http://msdn.microsoft.com/library/en-us/spptsdk/html/soapmlistsgetlistitems.asp

    hth
    //AndersR

    //AndersR
  • 02-06-2006 07:30 PM In reply to

    • v-luchen
    • Not Ranked
    • Joined on 01-20-2006
    • China
    • Posts 6

    Re: How can I get the Value from a SharePoint List?

    Hi AndersR
    I think the first way is good for me,but I want to know How can I fetch all the data from the a list,and then put them in a datatable.
    Can you give me example about this?
  • 02-07-2006 12:34 AM In reply to

    Re: How can I get the Value from a SharePoint List?

    Hi V-luchen and welcome to our forum!
    Matt Faus's new HowTo will help you. Should be release today or tomorrow. Go tohttp://www.infopathdev.com and look for it. It's titled "Add SharePoint List Items with InfoPath". Cheers!

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 02-07-2006 01:28 AM In reply to

    • v-luchen
    • Not Ranked
    • Joined on 01-20-2006
    • China
    • Posts 6

    Re: How can I get the Value from a SharePoint List?

    Thanks for your help,
    I want to an example,how to retrieve all items of SPS list at one time(basic C# code,don't use SPS web service)
  • 02-07-2006 12:28 PM In reply to

    Re: How can I get the Value from a SharePoint List?

    Hi again,

    I recommend reading the SPPT or WSS SDK or check the article section of MSDN for relevant info.

    In basic what you need to do is
    1. in VS.NET add a web reference pointing tohttp://yourportal/subarea/_vti_bin/lists.asmx
    2. use the method GetListItems("listname/listguid",null,null,null,null,null) <- here you can define special views, queries, fields, rows and options
    3. what youll get back is an XML node containing a soap envelope wich you can parse/query as needed using xpath.

    (untested from the top of my head)
    XmlNode returnXml = myListService.GetListItems("myList","myView",null,null,null,null);
    System.Diagnostics.Debug.WriteLine(returnXml.xml,"returnXml");

    hth
    //AndersR

    links to MSDN SPPT articles and SDK:
    http://msdn.microsoft.com/library/?url=/library/en-us/odc_2003_ta/html/odc_landsppt03_ta.asp?frame=true


    //AndersR
  • 02-07-2006 06:36 PM In reply to

    • v-luchen
    • Not Ranked
    • Joined on 01-20-2006
    • China
    • Posts 6

    Re: How can I get the Value from a SharePoint List?

    Hi AndersR:
    Thanks for your help!
    I can do this by using SPS web service
    Now,I want to do it by using sencondary data connection
    My secondary data connection was not setup to “automatically retrieve data when the form is opened”

    The secondary data connection is setup when I click a button. My code is as follows:

    [InfoPathEventHandler(MatchPath="Recieve", EventType=InfoPathEventType.OnClick)]

    public void Recieve_OnClick(DocActionEvent e)

    {

    thisXDocument.DataObjects["ProjectsStatus"].Query();//”ProjectsStatus” is my secondary data connection name

    }

    NOW, I want to retrieve all the data of the SPS list, and put them in a datatable.

    How can do this by using C# code?

    Can you give me a sample about use
    "programmatically using XDocument.DataAdapters("YourListName").DOM.xml (DataObject of type SharepointListAdapter )
    "
  • 02-09-2006 04:52 AM In reply to

    Re: How can I get the Value from a SharePoint List?

    Hi

    i dont have specific code for that, but ill give you a hint (untested):

    youll need a

    XmlDocument document = new XmlDocument();
    document.LoadXml(yourDataAdapter.DOM.xml); //there could be more clever methods to do this so check DataAdapter DOM property
    //also you should check for errors in return xml. i think i recall its in "//sp:errorCode"

    //Before you can select nodelists from XML dom, you need to add namespaces from return xml in your document. below i just add them all since i dont recall wich is needed:

    //define SPS namespaces
    const string SharePointNamespacePrefix = "sp";
    const string SharePointNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/";
    const string ListItemsNamespacePrefix = "z";
    const string ListItemsNamespaceURI = "#RowsetSchema";
    const string PictureLibrariesNamespacePrefix = "y";
    const string PictureLibrariesNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/ois/";
    const string WebPartsNamespacePrefix = "w";
    const string WebPartsNamespaceURI = "http://schemas.microsoft.com/WebPart/v2";
    const string DirectoryNamespacePrefix = "d";
    const string DirectoryNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/directory/";
    const string RowSetNamespaceURI = "urn:schemas-microsoft-com:rowset";
    const string RowSetNamespacePrefix = "rs";

    // associate with the xmlns namespaces
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
    nsmgr.AddNamespace(SharePointNamespacePrefix,SharePointNamespaceURI);
    nsmgr.AddNamespace(ListItemsNamespacePrefix,ListItemsNamespaceURI);
    nsmgr.AddNamespace(PictureLibrariesNamespacePrefix,PictureLibrariesNamespaceURI);
    nsmgr.AddNamespace(WebPartsNamespacePrefix,WebPartsNamespaceURI);
    nsmgr.AddNamespace(DirectoryNamespacePrefix,DirectoryNamespaceURI);

    //now select the nodelist you want to iterate
    XmlNodeList listItems = document.SelectNodes("//rs:data",nsmgr);//im not sure about the return xml syntax but think its rs:data

    for ( int c=0; c < listItems.Count; c++ )
    {
    //here you add data to your dropdown or whatever in InfoPath
    }

    hope this intermistic code sample helps -anyways its all i have time for ;-)

    //AndersR

    //AndersR
  • 04-17-2007 11:35 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: How can I get the Value from a SharePoint List?

    Hi,

     Go through this article you will get the one file and if you change in your search value contains then you can use the instead on using <Eq> use <Contains>. It will give the node list which contains the value of given search value.

    http://www.infopathdev.com/blogs/agni/archive/2006/05/15/Query-for-Items-in-SharePoint-Form-Library-Using-GetListItems-Web-Method.aspx

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