title: How do I programmatically nullify a File Attachment in InfoPath Forms
body: <p>I'm running into a problem with some InfoPath C# code while trying to remove an attachment from a form.</p>
  
  <p>Basically the process is:</p>
  
  <ol>
  <li>User opens form</li>
  <li>User clicks button</li>
  <li>File attachment is cleared</li>
  </ol>
  
  <p>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.</p>
  
  <pre><code>public void BTN_ClearAttachment_Clicked(object sender, ClickedEventArgs e)
  {
     try
     {
         _OriginalAttachment.SetValue(_BLANK_ATTACHMENT.Value);
     }
     catch (Exception ex)
     {
         _ErrorField.SetValue(ex.Message + " : " + ex.StackTrace);
     }
  }
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>Dr Z</p>
  
  <p>Edit - P.S.  I should clear up that both _OriginalAttachment &amp; _ErrorField are both XPathNavigators, pointing at different schema elements.  I've verified that these XPathNavigators are both pointing at valid schema elements.</p>