Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Travis Nelson 7 posts 27 karma points
    Aug 30, 2016 @ 20:35
    Travis Nelson
    0

    Export Data as CSV from C# Code

    I'd like to be able to export data from Umbraco Forms (Entries) in the same format you get when you download from the backoffice. I've looked at the Forms APIs RecordStorage, FormsStorage, and things like ExportToExcel but can't seem to assemble them together to get what I need. The biggest problem I'm facing is the disconnect between the field labels and the data; the JSON+SQL storage makes brute forcing the whole thing messy.

    In short, I just want to know if there is a public API in Umbraco Forms to export the exact data I'd get by clicking the "Export" button on the Entries page.

    Thank you! Travis

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 31, 2016 @ 08:02
    Warren Buckley
    0

    Hello Travis,
    In Umbraco Forms it does not export to CSV, due to many problems users reported due to data submitted containing comma's etc that would then thus break the structure of the CSV file.

    So now Umbraco Forms directly exports to Excel file instead because of this.

    I am curious in what you are trying to achieve if you want to call this directly from code, rather than use the Umbraco Forms UI.

    If you are wanting to add a new export option type such as saving this to a CSV file then you could create a new export provider class.

    But I am not 100% sure if that is what you are trying to achieve.

    Once I get a clearer idea, I can help a bit more.

    Thanks,
    Warren

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 31, 2016 @ 08:29
    Warren Buckley
    0

    However here is a way to invoke the excel export provider using code

    var excelProvider = Umbraco.Forms.Core.Providers.ExportTypeProviderCollection.Instance.GetProviderInstance(Guid.Parse(Core.Constants.ExportTypes.Excel));
    excelProvider.ExportToFile(recordFilter, "someFilePath");
    

    Hope this is enough to get you started to what you would like to do.

  • Travis Nelson 7 posts 27 karma points
    Aug 31, 2016 @ 14:51
    Travis Nelson
    0

    Thanks Warren. I will take a look at this and see if it does what I need. Also, if it's supported in the version of Forms we're using.

    In short, my client has a process that reads the exported .csv file (our version exports .csv--is that different now?) and imports the data into their ERP software. The problem is that someone has to log in and manually download the file and copy it to a server. I'm trying to automate that process for them.

    Hope that makes sense. If there's a better way please let me know!

  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 10:05
    Jay
    0

    Hi Warren,

    Where do you put this code to invoke the excel export provider?

    Thanks

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 31, 2016 @ 15:02
    Warren Buckley
    0

    Well you could do that and upload an exported file for them. But have you thought about creating a custom workflow provider for them.

    So that every form submission is submitted to the ERP system directly if it has an API perhaps? This means you would not need to create some form of scheduled task to automate creating the export file & doing the upload, additionally the client would then have always upto date data in their ERP system.

    Thanks,
    Warren

  • Travis Nelson 7 posts 27 karma points
    Aug 31, 2016 @ 15:07
    Travis Nelson
    0

    Yeah, that's something we'll be doing also, and will probably become the main way to ship the data at some point. We started down the path of exporting data because we have several forms with lots of submitted data, and their ERP system doesn't currently have an exposed API to push to. Corporate IT, firewalls, security concerns, all things out of our control. :)

  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 09:29
    Jay
    0

    Hi Warren,

    I'm using Umbraco Forms 4.1.0 and the option to export is exporting to CSV. Can you guide me on how I can make the amends to export that to Excel instead (due to the comma from the users while entering the form is causing the issues when I display the exported CSV).

    Thanks

  • Tom Black 1 post 71 karma points
    Sep 21, 2020 @ 05:47
    Tom Black
    0

    Hi, Travis Nelson. I appreciate it. But you can try ZetExcel for export data to excel C#.

Please Sign in or register to post replies

Write your reply to:

Draft