简体   繁体   中英

Read CSV file selected at client side in C# through AJAX?

I have a requirement in which user will select a CSV file locally, I have to read the file contents and dump them on a JQGrid. Yes, the browser is IE :)..What should I do in order to achieve this?

Actually you can do that with the all new HTML5 features, so if you are going for IE9+

http://www.html5rocks.com/en/tutorials/file/dndfiles/

Check this out.

Basically, you need the FileReader component ( FileReader.readAsText(Blob|File, opt_encoding) ) and then just parse everything with regexps or whatever floats your goat.

If, you definetely need to do this in client side AND in older IE, maybe ActiveX is a solution:

ActiveX' FileSystemObject

Barring that you are not capable of using HTML 5 (lower version of ie etc.):

Javascript can't access the file system directly, so you are going to have to use the file upload tag and parse it on the server: http://webdesign.about.com/od/htmltags/p/input-file-tag.htm

You can then use AJAX to query the contents and pull it back down into the grid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM