Query Form Library - InfoPath Dev
in

InfoPath Dev

Query Form Library

Last post 06-23-2010 04:11 AM by aikin_dm. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-20-2005 04:10 PM

    Query Form Library

    I know that it is possible to populate other fields based on the input of a certain field that uses a rule to query a sharepoint "list".

    I need to do the same but use a form library. Is this possible?

    The only results I have been getting is that the query returns the first entry in the library.
  • 07-20-2005 06:10 PM In reply to

    Sure. I posted some sample code on Microsoft's public form the other day:

    public void SharePointListAdapterDropDown_OnAfterChange(DataDOMEvent e)
    {

    // filter out noise
    if (e.IsUndoRedo || "Insert" != e.Operation || "" == e.NewValue)
    return;

    // prevent infinite loops when loading files from ShP
    if(true == fGettingSharePointFile)
    {
    fGettingSharePointFile = false;
    return;
    }
    fGettingSharePointFile = true;

    // get the selection
    string sKey = e.Site.text;

    // "test" is the name of your sharePoint list adapter data connection
    SharepointListAdapter oSpla =
    (SharepointListAdapter)thisXDocument.DataAdapters["test"];
    sUrl = oSpla.SiteUrl;

    // "test" is also the name of a secondary data source that you will
    pre-populate
    IXMLDOMDocument2 oDom = (IXMLDOMDocument2)thisXDocument.GetDOM("test");
    oDom.setProperty("SelectionNamespaces",
    "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolut
    ion\"");
    // filter on the value using sKey
    string sName =
    oDom.selectSingleNode(string.Format("//dfs:test[@key1=\"{0}\"]/@Value",
    sKey)).text;

    // Note: you need to set sSP_FOLDER to your SharePoint folder
    // - you can do this programmatically using SolutionURL and walking up the
    string sFilename = sUrl + sSP_FOLDER + sName;

    // random schema - please change to suit your insertion needs
    IXMLDOMNode oParentNode = getNode("//my:root/my:section1");
    IXMLDOMNode oNode = getNode("//my:root/my:section1/rd:section2");

    // Load the XML DOM from the 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.infopathdev.com/Samples/ShP/GetFile\"
    xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"
    xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-1
    7T17:30:19\"
    xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\"");

    // Note: be careful calling replaceChild since it can be slow
    IXMLDOMNode oNewNode = oXml.selectSingleNode("//my:root/my:section1//" +
    oExistingNode.nodeName);
    oParentNode.replaceChild(oNewNode.cloneNode(true), oExistingNode);

    return true;
    }


    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 06-23-2010 04:11 AM In reply to

    Can you query a form library in Infopath 2003 without using any code.

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