How To: Kinetic - Upload a Client File, Parse, and Display in a Grid

Another How To for how to use the File Picker Client control and file-erp-transfer widget.
This tutorial will go over how to wire up the controls, pass the file to a function, parse the data, return the dataset to App Studio, and display the rows in a grid.

  1. Create a DataView holder

  1. Create a grid and bind it to the new DataView from Step 1.

  1. Add the File Picker Client (or server) control to your form and bind it to something. I used TransView because it’s runtime and I don’t need to save the file after the fact.

  1. Add a button and create an OnClick event for it.

  2. In the OnClick event, add the file-transfer-erp widget. This will upload the file from your client to the server.

Special Folder - This will be the directory accessible to you on the server (yes, even you SaaSy folks!). I typically just use CompanyData
Server Path - If you want it at the root, just set it to the EpBinding that you set your File Picker to be (Mine is TransView.File) with the standard {} syntax. I’m adding an additional directory to mine called “Uploads”, but this is something only On Prem folks can do, I believe. Or else, you would need support to add it for you.
Client Path - Didn’t see a need for this.
Company - Optional, Company ID
Transfer Type - Upload to, well, upload!!
ErpFileBoxID - This is the ID from your File Picker Client control

  1. On the file-transfer-erp widget, click on Behavior → OnSuccess and wire it to an erp-function widget

  1. Pass in the file name from the control’s binding

  1. Set up the response based on how you wrote/named your function.

Parameter Name - The name of the DataTable
View Name - The View that you created in step 1
Parse from Response Path - Your DataSet output parameter from the function

  1. Create and set up your function (If you use mine, you’ll need to edit it and change the server path)
    MISC2.efxb (2.5 KB)

using System.IO;

string filePath = @"\\SERVER\EpicorData\APP\Companies\Company\Uploads\"; //Change this to be your server location to where you uploaded the file from the erp-file-transfer widget
bool locked = true;

// Waits until the file is done being combined
  locked = false;
      FileStream fs =
          File.Open(Path.Combine(filePath, FileName), FileMode.Open,
          FileAccess.Read, FileShare.None);
  catch (IOException ex)
      locked = true;
while( locked );

using( StreamReader sr = new StreamReader(Path.Combine(filePath, FileName)) )
  string row = "";
  DataSet thisDS = new DataSet();
  DataTable dt = thisDS.Tables["CSVRows"];
  while(!string.IsNullOrEmpty(row = sr.ReadLine()))
    string[] cols = row.Split(','); 
    var dr = dt.NewRow();
    // You can be more creative with the column headers here
    for(int i = 0; i < cols.Count(); i++)
      if( !dt.Columns.Contains("Col" + i.ToString()) )
        dr.Table.Columns.Add("Col" + i.ToString());
      dr["Col" + i.ToString()] = cols[i].ToString().Replace("\"","");
  OutDS = thisDS;


Special thanks to @klincecum for poking the file transfer bit.


Great work! Thanks to both of you.

I can do it :slight_smile:

But anyway, nice job writing it up. I’m sure I’ll reference it in the future.

As far as your function, I believe Epicor has a prebuilt class or helper method that parses CSV files
for us if we can find it.

I just assume SaaS-a-frass can’t do anything except cry in frustration. :slight_smile:

Interesting! I’ll take a gander.

Now which library I came across it in is anyone’s guess. I didn’t use it, just saw it :slight_smile:

See the top part of this post.

@hasokeric :metal: