Programmatically export Infopath form to csv file - InfoPath Dev
in

InfoPath Dev

Programmatically export Infopath form to csv file

Last post 01-01-2010 03:59 PM by eddyblanco. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-30-2009 11:16 AM

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Programmatically export Infopath form to csv file

    I created an InfoPath 2003 form. I am trying to programmatically export some of the data into many different csv files. However, I have been unable to find a way to programmatically export the data. Does anybody have any suggestions? Thank you,

    -Lawson

  • 01-01-2010 03:59 PM In reply to

    Re: Programmatically export Infopath form to csv file

    Hello Lawson. In order to export the content of an infopath form you would need to:

    1) Open the XML

     2) Read all nodes or the specific node you would like to export to excel in your case.

     For reading you coud do something similar to the following sample.

                            file = yourfile.xml;

                            string xmlFileContent = System.Text.Encoding.Default.GetString(file.OpenBinary());
                            int index = xmlFileContent.IndexOf("<?xml");
                            if (index != 0)
                                xmlFileContent = xmlFileContent.Remove(0, index);

                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(xmlFileContent);
                            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                            mgr.AddNamespace("my", @"http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-06-10T00:13:44");


                            //the sample node to read
                            XmlNode nodeStatus = doc.DocumentElement.SelectSingleNode("/my:Eddys_Form/my:PlanHistory_Status", mgr);
                           

                           string insertsomewhere = nodeStatus.InnerText.tostring();

    For the insert into the csv there are plenty of samples in the internet. just pass the string above.

    I hope this heps.

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.