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