How do I programmatically nullify a File Attachment in InfoPath Forms

Posted by Doctor Zinda on Stack Overflow See other posts from Stack Overflow or by Doctor Zinda
Published on 2010-02-22T21:48:21Z Indexed on 2010/03/25 20:33 UTC
Read the original article Hit count: 243

Filed under:

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:

  1. User opens form
  2. User clicks button
  3. 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.

© Stack Overflow or respective owner

Related posts about infopath-2007