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.

ADVERTISEMENTS

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",
    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.

 


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.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services