Passing Parameters - InfoPath Dev
in

InfoPath Dev

Passing Parameters

Last post 05-22-2010 10:46 PM by Lawson. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-22-2010 09:16 PM

    • Lawson
    • Top 100 Contributor
    • Joined on 12-23-2009
    • Virginia
    • Posts 91

    Passing Parameters

    I have an IP 2003 form with C# code. I have a button with the following code:

     

    XDocument newForm = thisApplication.XDocuments.NewFromSolution(@"C:\Users\Lawson\Desktop\eFileroom Project\Forms\Modification (MR) Form Test 1.xsn");

    //CONVERT TO IXMLDOMDocument2

    IXMLDOMDocument2 newFormDom = (IXMLDOMDocument2)newForm.DOM;

     

     

    //Set the namespace (correct for the appropriate namespace for template)

    newFormDom.setProperty("SelectionNamespaces", "xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-10T22:57:46\"");

     

     

    newFormDom.selectSingleNode(
    "/dfs:myFields/my:MetaDataSection/my:Contractor").text = Contractor;newFormDom.selectSingleNode("/dfs:myFields/my:MetaDataSection/my:Value").text = Value;

     

    However, everytime I press the button I get the following exception:

     System.Runtime.InteropServices.COMException was unhandled by user code
      Message="Reference to undeclared namespace prefix: 'dfs'.\r\n"
      Source="msxml5.dll"
      ErrorCode=-2147467259
      StackTrace:
           at Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode.selectSingleNode(String queryString)
           at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMDocument50Wrapper.selectSingleNode(String queryString)
           at Form_Creator_A.FormCode.CTRL15_5_OnClick(DocActionEvent e) in C:\Users\Lawson\Documents\InfoPath Projects\Form Creator A1\FormCode.cs:line 121
           at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

     

    I've gotten this code to run before. Does anybody know where I'm going wrong?

     

  • 05-22-2010 09:45 PM In reply to

    Looks like you need to add dfs to the selection namespaces for that DOM.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-22-2010 10:15 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-23-2009
    • Virginia
    • Posts 91

    I tried the following:

    newFormDom.setProperty("SelectionNamespaces", "xmlns:dfs=\http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\");

    but I still get the same exception

  • 05-22-2010 10:22 PM In reply to

     I presume this time you got an exception about the my namespace.  If you're going to use them both in your XPath, you need to declare them both.

     newFormDom.setProperty("SelectionNamespaces", "xmlns:dfs=\"http://uri1\" xmlns:my=\"htp://uri2\"");

    Probably just a side-effect of the URI getting converted into a link, but you should note that your previous post is missing quotation marks after the backslashes.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-22-2010 10:31 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-23-2009
    • Virginia
    • Posts 91

    Your presumption is right.

    Tried the following:

    newFormDom.setProperty("SelectionNamespaces", "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-10T22:57:46"");

    Geting following errors 

     

    Error 1 Newline in constant C:\Users\Lawson\Documents\InfoPath Projects\Form Creator A1\FormCode.cs 117 228 Form Creator A
    Error 2 ) expected C:\Users\Lawson\Documents\InfoPath Projects\Form Creator A1\FormCode.cs 117 228 Form Creator A
    Error 3 ; expected C:\Users\Lawson\Documents\InfoPath Projects\Form Creator A1\FormCode.cs 117 231 Form Creator A

  • 05-22-2010 10:46 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-23-2009
    • Virginia
    • Posts 91

    Nevermind, didn't have the \ in the last one.

    Thanks for your help man.

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