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

by S.Y.M. Wong-A-Ton

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 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",
    attachment.LookupNamespace("xsi")))
    {
    attachment.SetValue("");
    attachment.CreateAttribute(
    "xsi", "nil",
    attachment.LookupNamespace("xsi"), "true");
    }

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

 Subscribe (RSS | Email)

Related Posts

Comments to this post were closed 30 days after it was published.

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 of S.Y.M. Wong-A-Ton. Usage of 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, S.Y.M. Wong-A-Ton.

Working with InfoPath