Removing InfoPath Attachments

  • 10 January 2006
  • 7 replies
  • 3 views

Badge +2
Hi,

Does anyone know how to remove attachments from an InfoPath form? I have saved the attachments to a Share Point site and now wish to delete the attachments from the InfoPath form.

Any advice would be appreciated.

7 replies

Badge +4
Use the Sharepoint 2003 Document event to remove the file from sharepoint. Follow the wizard instructions.
Badge +2
I'm trying to remove the attachment from the InfoPath document (not the SharePoint site)
Badge +8
You could use a server event to manipulate the K2InfoPathSchema XML datafield to remove the docattachment element that you want to get rid of.
Badge +2
Thanks, we ended up doing that (using the server event). We added a code module to and called the method from there. I've included some sample code should anyone ever want to do the same thing:

public static void RemoveAttachments(ref ServerEventContext K2)
{
System.Xml.XmlDocument oXMLDoc = new System.Xml.XmlDocument ();
oXMLDoc.LoadXml(K2.ProcessInstance.XmlFields["K2InfoPathSchema"].Value);

System.Xml.XmlNode irRequest = oXMLDoc.SelectSingleNode("/*[local-name()='IRRequest']/*[local-name()='Attachments']");
for(int counter = irRequest.ChildNodes.Count; counter > 0; counter--)
{
if(irRequest.ChildNodes.Count > 0)
{
// deleting the attachments
if(irRequest.ChildNodes.Count > 1 )
{
// if there are more than attachment nodes, delete all but one
for(int aCounter = irRequest.ChildNodes.Count; aCounter > 1; aCounter--)
{
irRequest.ChildNodes.Item(aCounter-1).ParentNode.RemoveChild(irRequest.ChildNodes.Item(aCounter-1));
}
}
// clear the file from the final file node
if ( irRequest.ChildNodes.Count == 1 )
{
System.Xml.XmlElement xmlAtt = (System.Xml.XmlElement)irRequest.ChildNodes.Item(0).FirstChild;
xmlAtt.SetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
irRequest.ChildNodes.Item(0).FirstChild.InnerText = "";
}
}
}
}
Badge +11
Thank you for posting your solution. This is exactly what we would like to see - members helping the K2.net community with their experience and sample code.

Regards,
Ockert
Badge +3
Actually, could you shed some light on how you got the attachment in the Infopath form to post to a Sharepoint library? I can't seem to figure this out.

thanks,

Jason
Badge +8
could you shed some light on how you got the attachment in the Infopath form to post to a Sharepoint library?

Please have a look at the K2.net SharePoint 2003 Multiple Documents event in K2.net Studio. On the second page of the wizard, select the option 'XML Document that contains attachments' and point it to the K2InfoPathSchema XML datafield and supply the relevant XPaths.

You can also have a look in the K2Studio help file - search for 'SharePoint 2003 Multiple Documents Event'

Hope this helps!

Reply