CSV export via Jscript - InfoPath Dev
in

InfoPath Dev

CSV export via Jscript

Last post 02-21-2007 02:03 PM by Greg Collins. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 02-19-2007 12:27 AM

    CSV export via Jscript

    Hi guys,

    I haven't been using Infopath for very long (72h max), but seem to have exhausted my patience and can't seem to find a proper answer to my question in the various .CMHs, MSDN and forums.

    I am editing a an Infopath for that uses a repeating table as an editing log (ie. Film, Start, End, Duration etc.)

    Now accessing the info with Jscript was not that much of an issue but it seems that it's not possible to export said information (automatically) in Infopath.

    I have attached the code for the export button below (strOutput usually holds a lot more lines), but evertime I am press export when running the form i get the following error:

    "Bad file name or number"

    It seems that the Jscript can't open the file for writing. I have
    tried many different other locations and checked that the file is definately in place.

    Really out of ideas atm and I can understand why something so simple would be a problem in Infopath.

    Any help would be very much appreciated.

    function btnExport::OnClick(eventObj)
    {
    var strOutput = "Sometext\tSome more text\tThe end\n";

    var fso, tf;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    tf = fso.CreateTextFile("c:\dev\test.txt", true);
    tf.Write (strOutput);
    tf.Close();
    }
  • 02-19-2007 09:44 AM In reply to

    What you are attempting to do requires full-trust security. Have you set your form to full-trust and either signed it or used regform.exe to make an installable .msi for your form?
  • 02-19-2007 04:38 PM In reply to

    Thanks for the quick reply Greg.

    I have set the form to full-trust and it is signed as well, yet
    the script still doesn't want to play along.

    Any other ideas as to what the problem might be, or where I might
    have gone wrong?
  • 02-20-2007 09:27 AM In reply to

    Have you verified that your code works outside of InfoPath?

    One thought is that you might need to escape your backslash character... i.e.:

    tf = fso.CreateTextFile("c:\\dev\\test.txt", true);

    Not sure if that will make a difference, but as the error is complaining about the filename, it seems a likely possibility.
  • 02-20-2007 04:27 PM In reply to

    Hi Greg,

    thanks a lot for the hint. I feel pretty stupid now, seeing as I should have really picked that up myself. I copied the code from the JScript reference in the IP help, but must have muddled up the paragraphs with
    the VBScript example, which uses "normal" paths ala "c:\dev\foo"

    cheers,
    Ben
  • 02-21-2007 02:03 PM In reply to

    Glad to have helped! Take care!
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.