Delete, remove, or clear an attachment from an InfoPath form

Filed under: InfoPath 2007

Learn how you can delete or clear an attachment field on an InfoPath form manually or through code.


In InfoPath, if you want to delete an attached file, you could:

  1. Remove the InfoPath file attachment manually; or
  2. Clear the attachment field programmatically.

To delete an attachment manually:

  1. Click on the paperclip icon in front of the attachment field.
  2. Select Remove from the context menu that appears.

To delete an attachment through code:

  1. Add an event handler to the InfoPath form template.
  2. Add code similar to the following to the event handler:

    XPathNavigator root = MainDataSource.CreateNavigator();
    XPathNavigator attachment = root.SelectSingleNode(
    "//my:attachment", NamespaceManager);

    if (!attachment.MoveToAttribute("nil",
    "xsi", "nil",
    attachment.LookupNamespace("xsi"), "true");

    Note: my:attachment represents the File Attachment control on the InfoPath form.


Related Posts


Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.