views:

138

answers:

1

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.

A: 

Figured it out. The way I did it was to call ReplaceSelf(string) and pass in a blank version of the XML node.

public void BTN_ClearAttachment_Clicked(object sender, ClickedEventArgs e)
{
   try
   {
       _OriginalAttachment.ReplaceSelf("<my:OriginalAttachment></my:OriginalAttachment>");
   }
   catch (Exception ex)
   {
       _ErrorField.SetValue(ex.Message + " : " + ex.StackTrace);
   }
}

This alleviated any errors I was running into.

Doctor Zinda