In InfoPath, if you want to delete an attached file, you could:
- Remove the attachment manually; or
- Clear the attachment field programmatically.
To delete an attachment manually:
- Click on the paperclip icon in front of the attachment field.
- Select Remove from the context menu that appears.
To delete an attachment through code:
- Add an event handler to the InfoPath form template.
- 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.

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