Adding another attachment field - InfoPath Dev
in

InfoPath Dev

Adding another attachment field

Last post 02-10-2010 03:09 PM by Lawson. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-10-2010 11:51 AM

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

    Adding another attachment field

    I have an InfoPath 2007 form that uses the Microsoft example Encoder and Decoder found at the following website. http://support.microsoft.com/kb/892730

     

    I would like to add one more attachment field to the save button, so when the save button is clicked, the contents of both attachment fields are saved to the specified folder.

     

    The save button has the following code.

    [InfoPathEventHandler(MatchPath = "btnSave", EventType = InfoPathEventType.OnClick)]public void btnSave_OnClick(DocActionEvent e)

    {

    //Get a reference to the attachment node.

    IXMLDOMNode n = thisXDocument.DOM.selectSingleNode("my:myFields/my:theAttachmentField");

    //Get the text of the node.

    String theAttachment = n.text;if (theAttachment.Length > 0)

    {

    InfoPathAttachmentEncoding.InfoPathAttachmentDecoder myDecoder = new InfoPathAttachmentEncoding.InfoPathAttachmentDecoder(theAttachment);

    myDecoder.SaveAttachment(@"C:\Users\Lawson\Documents\InfoPath Forms");

    }

    -------------------------------------------------------------------------------------------------------------------------- 

    I added the following code in an effort to save the second attachment like the first.

     

    //Get a reference to the attachment node.

    IXMLDOMNode nn = thisXDocument.DOM.selectSingleNode("my:myFields/my:theAttachment2Field");

    //Get the text of the node.

    String theAttachment2 = nn.text;if (theAttachment2.Length > 0)

    {

    InfoPathAttachmentEncoding.InfoPathAttachmentDecoder myDecoder = new InfoPathAttachmentEncoding.InfoPathAttachmentDecoder(theAttachment2);

    myDecoder.SaveAttachment(@"C:\Users\Lawson\Documents\InfoPath Forms");

    }

    However, I get the following message after I debug the form and try to test it.  

    NullReferenceException was unhandled by user code.

    Object reference not set to an instance of an object.

    TroubleShooting tips:Use the “new” keyword to create an object instance. For this line     String theAttachment2 = nn.text;       Does anybody have any suggestions on how to either fix this error, or go about this a different way? Thanks,-Lawson 

     

  • 02-10-2010 12:18 PM In reply to

    Re: Adding another attachment field

    Are you sure of your XPath:

    my:myFields/my:theAttachment2Field

    Did you use the Copy XPath menu option in the Data Source Task Pane to get that XPath to your field? In the Data Source Task Pane, make sure your Main data source is displayed, and right click on the field and select Copy XPath. Then paste that XPath into your code:

    IXMLDOMNode nn = thisXDocument.DOM.selectSingleNode("my:myFields/my:theAttachment2Field");

    Replacing the original XPath with the one you just copied from the data source.

    Hilary Stoupa

  • 02-10-2010 12:43 PM In reply to

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

    Re: Adding another attachment field

    Hilary,Once again, you're AWESOME!I made the necessary changes, and the problem has been solved.Thanks for all of your help.-Lawson 

     

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

    Re: Adding another attachment field

    You are very welcome, and your dog (I'm assuming the dog in your profile pic is yours?) is ADORABLE!

    Hilary Stoupa

  • 02-10-2010 03:09 PM In reply to

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

    Re: Adding another attachment field

    Ha, thanks, he's my sidekick :)

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