InfoPath File Attachments

  • 3 December 2008
  • 4 replies
  • 4 views

Badge +6

I am a new to K2 Workflow. I have a InfoPath form where users can add Multiple attachments, each one has more than 3 to 5 MB. Due to performance Issue, we donnot want to save in XML instead we want to save all the files to SharePoint Directly. That means, InfoPath should not contain any file attachments encoded in XML instead it should have a Hyper link to SharePoint Library where user can download.


I used the "SharePoint Document Event Wizard" to copy the files from InfoPath to SharePoint Library. it works great. But InfoPath Form still has file Encoded in XML. 


So, how to achive this functionality using K2? Please throw me some ideas on this.


I will appreciate any help.


Thanks


Vijay


4 replies

Badge +2

Hi,

 After you copy the attachments to Sharepoint, you only need remove the attachments nodes in the Infopath XML.

Badge +6

Thank you very much for your reply. I need little more help, How to remove the Attachments for XML using K2. Normally, if i use InfoPath Code Behind, i can write a code to remove the file Encode form XML. But i dont know whether K2 has any out of box feature to do this.

Badge +6

Hi,

this is an interesting question. I thought blogged on that, but I didn't do it :-(. Unfortunately, K2 doesn't provide out-of-the-box native component to do this. So, as someone proposed you, you can add a server event just after the Sharepoint Document event you use, and you will delete the file from the form manipulating XML. Here is a sample of the code you need to write:

        using System.Xml;
        public void Main(Project_<YOURGUID>.EventItemContext_<YOUR2NDGUID> K2)
        {
            //Change the date regarding to your form
            string my = @"http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-24T15:27:08";

            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(K2.ProcessInstance.XmlFields["<FormName>"].Value);

            XmlNamespaceManager nsMgr = new XmlNamespaceManager(xDoc.NameTable);
            nsMgr.AddNamespace("my", my);

            int i = 0;
            foreach (XmlNode node in xDoc.DocumentElement.SelectNodes("//my:myFields/my:<GROUP1>/my:<DOCVARNAME>", nsMgr))
            {
                if (i == 0)
                {
                    //For the first item, we just delete the value
                    node.RemoveAll();
                }
                else
                {
                    //For new items, we delete the node
                    xDoc.DocumentElement.SelectSingleNode("//my:myFields/my:<GROUP1>", nsMgr).RemoveChild(node);
                }
                i++;
            }
            K2.ProcessInstance.XmlFields["<FormName>"].Value = xDoc.InnerXml;
        }

Remark : You can add to this code a line to add a link to the Sharepoint Doc Lib using this line :

xDoc.DocumentElement.SelectSingleNode("//my:myFields/my:<GROUP1>/my:<LinkVar>", nsMgr).InnerText = "<LinkToYourDocs>";

 

But it exists alternative way: You can use a blackmarket project doing this : http://www.k2underground.com/k2/ProjectHome.aspx?ProjectID=54 (written by Charles Emes - K2 Insider)

HTH

Badge +9
Unfortunately, removing the file attachment xml in a server event does not prevent the fact that the InfoPath form has to actually upload and then submit with the file attachment xml.  I would propose creating a 'file attachments' web form that you open from your InfoPath form via popup to handle the file attachments and simply giving urls back to InfoPath.  There is a bit of work involved with this approach, to be sure, but allowing InfoPath to manage your files in any way - particularly if they are over 10mb or so - is a bad idea for performance reasons.

Reply