This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Load a CSV file from a form and process with C#

esteimle - Friday, January 13, 2012 1:49 PM:

I want to have the user load a .csv file that contains bom information, then process that file in C# and store the data in the database.   I can do the last part but so far I don't understand how to prompt the user to open a file from a form, and then pass that file location to a C# method for processing.   I'd really like to show that data in a grid after processing too before saving but that's the next challenge.

I tried adding a file item to a form but the browse buttons did nothing, and couldn't see any event that I could use to open a file browser.

 

Thank you,

-Eric



RobMcAveney - Friday, January 13, 2012 2:02 PM:

Prompting the user for a file can only be done client-side in Javascript.  You can either a) do the whole thing in Javascript or b) read the file in Javascript and pass the contents on to a C# server method.  Given that you want to load it into a grid anyway, I'd say you're better off with option a).  I would suggest using an Action to launch the Javascript method.  Here's some sample code to get you started:

var vault = top.aras.vault;
var fileName = vault.SelectFile();
var fileContents = vault.ReadText(fileName);
alert(fileContents);

Rob



esteimle - Friday, January 13, 2012 5:13 PM:

Thanks that worked great, I got stuck at first because I didn't realize ReadText returns null if another program (in my case excel) has the file open.   Now my csv data is loading into an html element on my form.   I can't figure out how to make that html element any bigger though.  It seems determined to stay at 1" x 1".   There weren't any width or height settings in the form element tabs.   What's the proper way to set the size of the element?   Try to force soemthing with css?

This is my html:

<script type="text/javascript">

top.aras.uiAddConfigLink2Doc4Assembly(document, "TreeTable");

</script>

<object id="MyGrid"

style="width:500;height:500;"

classid="../cbin/TreeTable.dll#Aras.Client.Controls.GridContainer">

</object>

 



esteimle - Friday, January 13, 2012 5:34 PM:

nm I was missing the px; as in 500px;