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.
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.
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
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
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
do
{
locked = false;
try
{
FileStream fs =
File.Open(Path.Combine(filePath, FileName), FileMode.Open,
FileAccess.Read, FileShare.None);
fs.Close();
}
catch (IOException ex)
{
locked = true;
}
}
while( locked );
using( StreamReader sr = new StreamReader(Path.Combine(filePath, FileName)) )
{
string row = "";
DataSet thisDS = new DataSet();
thisDS.Tables.Add("CSVRows");
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("\"","");
}
dt.Rows.Add(dr);
}
OutDS = thisDS;
}
Special thanks to @klincecum for poking the file transfer bit.
I played with the dataview-copy widget. Same issue. I appreciate the suggestion!
What’s strange is that the Debug Tool work as intended.
For example, I uploaded a CSV. I removed a column from the CSV file, then reuploaded it. The grid still displays the removed column, but the Debug Tool did remove the column.
The Debug Tool is a nice addition. It still forget about it sometimes and use the CTRL+ATL+V command to display the DataViews in the browser Developer Tools console.
Just found out that expanding / collapsing a panel does refresh the columns. It would be great if I could just find the event to trigger that grid refresh.
I may end up triggering a collapse / expand of the Import CSV panel after the import is done. Not an ideal solution though!
Where is the SpecialFolder path located? For instance, if I have CompanyData selected, is this going to drop it in my EpicorData\Companies\Company\ folder? If so, I may be creating a new help topic haha.
Wish all of these actions were better documented by Epicor
I know this is a bit of an aged thread but I was wondering if this is still working in the most current version. I’m getting an error when saving the function:
ParseCSV.cs(36,23): warning ECF1002: The ‘System.IO.File.Open(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare)’ method cannot be called.
ParseCSV.cs(48,38): warning ECF1002: The ‘System.IO.StreamReader.StreamReader(string)’ constructor cannot be called.
We have a different function that gives errors like that when we save it, but the function then works fine. Our consultant has been told by Epicor that the errors we see are meaningless (and presumably will go away in the future).
For example, we see errors like this:
warning ECF1002: The ‘System.IO.File.AppendText(string)’ method cannot be called.
warning ECF1002: The ‘System.IO.Directory.GetFiles(string, string)’ method cannot be called.