How do I programmatically nullify a File Attachment in InfoPath Forms
- by Doctor Zinda
Howdy all,
I'm running into a problem with some InfoPath C# code while trying to remove an attachment from a form.
Basically the process is:
User opens form
User clicks button
File attachment is cleared
I've tried adding a blank attachment to my schema that never becomes populated, then setting the original field's value equal to that value by the method below. When debugging the form I catch an error: Schema validation found non-data type errors. Any tips here would be appreciated.
public void BTN_ClearAttachment_Clicked(object sender, ClickedEventArgs e)
{
try
{
_OriginalAttachment.SetValue(_BLANK_ATTACHMENT.Value);
}
catch (Exception ex)
{
_ErrorField.SetValue(ex.Message + " : " + ex.StackTrace);
}
}
Thanks,
Dr Z
Edit - P.S. I should clear up that both _OriginalAttachment & _ErrorField are both XPathNavigators, pointing at different schema elements. I've verified that these XPathNavigators are both pointing at valid schema elements.