Populate ListBox from SharePoint - InfoPath Dev
in

InfoPath Dev

Populate ListBox from SharePoint

Last post 04-04-2005 06:02 AM by Shanthi Reddy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-15-2005 08:18 PM

    • maggie
    • Not Ranked
    • Joined on 03-16-2005
    • Posts 1

    Populate ListBox from SharePoint

    I got this segment of code about how to populate a list box from a share point list. But I'm having a hard time in understanding it...Could anyone be kind enough to explain it to me how it works?

    quote:

    SharepointListAdapter oSpla =
    (SharepointListAdapter)thisXDocument.DataAdapters["SharePoint Adapter"];
    string sUrl = oSpla.SiteUrl;

    IXMLDOMDocument2 oDom =
    (IXMLDOMDocument2)thisXDocument.GetDOM("SharePoint Adapter ");
    oDom.setProperty("SelectionNamespaces",
    "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolut
    ion\"");
    string sTitle =
    oDom.selectSingleNode(string.Format("//dfs:SharePointAdapter[@Title=\"{0}\"]
    /@Title", sStandardTitle)).text;

    string sFilename = sUrl + sSP_HEADTRAX_FOLDER + sTitle;
    IXMLDOMNode oParentNode = getNode("//rd:Roles/rd:Role");
    IXMLDOMNode oNode = getNode("//rd:Roles/rd:Role/rd:HeadTrax");

    getSharePointFileData(sFilename, oParentNode, oNode);


    private bool getSharePointFileData(string sFilename, IXMLDOMNode
    oParentNode, IXMLDOMNode oExistingNode)
    {
    if("" == sFilename || null == oParentNode || null == oExistingNode)
    return false;

    try
    {
    IXMLDOMDocument2 oXml =
    (IXMLDOMDocument2)thisXDocument.CreateDOM();
    oXml.async = false;
    oXml.load(sFilename);
    oXml.setProperty("SelectionNamespaces",
    "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
    xmlns:rd=\"http://www.microsoft.com/WorldwideSalesOperations/Roles/Definitio
    ns/2004/Role\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"
    xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-02-0
    4T17:30:19\"
    xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\"");

    IXMLDOMNode oNewNode =
    oXml.selectSingleNode("//rd:Roles/rd:Role//" + oExistingNode.nodeName);
    oParentNode.replaceChild(oNewNode.cloneNode(true),
    oExistingNode);

    return true;
    }
    catch(Exception ex)
    {
    return false;
    }
    }



    Thanks in advanced!
  • 03-29-2005 04:29 PM In reply to

    Re: Populate ListBox from SharePoint

    Hi Maggie,
    How did you get that code?
    Cheers,
    Patrick

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 03-29-2005 06:02 PM In reply to

    Re: Populate ListBox from SharePoint

    i got it from you of course :)
  • 04-04-2005 06:02 AM In reply to

    Re: Populate ListBox from SharePoint

    Hello Maggie,
    Sorry for the late reply. Here is a brief explanation of the code.

    SharepointListAdapter oSpla =
    (SharepointListAdapter)thisXDocument.DataAdapters["SharePoint Adapter"];
    string sUrl = oSpla.SiteUrl;

    This code is used to get the URL from where you want to get the data.

    IXMLDOMDocument2 oDom =
    (IXMLDOMDocument2)thisXDocument.GetDOM("SharePoint Adapter ");
    oDom.setProperty("SelectionNamespaces",
    "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolut
    ion\"");
    string sTitle =
    oDom.selectSingleNode(string.Format("//dfs:SharePointAdapter[@Title=\"{0}\"]
    /@Title", sStandardTitle)).text;

    string sFilename = sUrl + sSP_HEADTRAX_FOLDER + sTitle;

    This code is used to get the DOM for this data connection and then get the sTitle (that is the filename of one of the files in that form library) based on one of the node values being equal to "sStandardTitle" and it gets the full path to this xml file.

    IXMLDOMDocument2 oXml =
    (IXMLDOMDocument2)thisXDocument.CreateDOM();
    oXml.async = false;
    oXml.load(sFilename);
    oXml.setProperty("SelectionNamespaces",
    "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
    xmlns:rd=\"http://www.microsoft.com/WorldwideSalesOperations/Roles/Definitio
    ns/2004/Role\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"
    xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-02-0
    4T17:30:19\"
    xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\"");

    This code creates a DOM called oXml and loads the data in the file whole full path we got above.

    IXMLDOMNode oNewNode =
    oXml.selectSingleNode("//rd:Roles/rd:Role//" + oExistingNode.nodeName);
    oParentNode.replaceChild(oNewNode.cloneNode(true),
    oExistingNode);

    This code then gets the data in that file and then replaces data in the Main DOM with this data. There is most probably a dropdown list box which gets data from these nodes.

    If you just want to populate a dropdown list box with data from a Sharepoint list (like its file name or any other promoted properties) then you can do this
    1. Create a data connection to the Sharepoint form library
    2. Insert a dropdown list box in the view and go to its properties window and choose the third radio button to get data from a data connection. Choose the appropriate data connection and the value that you want to show in the dropdown.

    Hope this helps!

    Shanthi
    InfoPathDev India
    Shanthi Reddy
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.