开发者

How do I programmatically nullify a File Attachment in InfoPath Forms

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜