[英]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. 我要求用户在本地选择一个CSV文件,我必须读取文件内容并将其转储到JQGrid上。 Yes, the browser is IE :)..What should I do in order to achieve this? 是的,浏览器是IE :) ..我应该怎么做才能实现这一目标?
Actually you can do that with the all new HTML5 features, so if you are going for IE9+ 实际上,您可以使用所有新的HTML5功能来做到这一点,因此,如果要使用IE9 +
http://www.html5rocks.com/en/tutorials/file/dndfiles/ http://www.html5rocks.com/zh-CN/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. 基本上,您需要FileReader组件( FileReader.readAsText(Blob|File, opt_encoding)
),然后只需使用正则FileReader.readAsText(Blob|File, opt_encoding)
或所有浮动的内容解析所有内容。
If, you definetely need to do this in client side AND in older IE, maybe ActiveX is a solution: 如果您确实需要在客户端和较旧的IE中执行此操作,则ActiveX可能是一种解决方案:
Barring that you are not capable of using HTML 5 (lower version of ie etc.): 除非您无法使用HTML 5(IE等的较低版本),否则:
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 Javascript无法直接访问文件系统,因此您将不得不使用文件上传标签并将其解析到服务器上: 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. 然后,您可以使用AJAX查询内容并将其拉回到网格中。
I would do it server side. 我会在服务器端做。
http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.fileupload.aspx
(FileUploadControl.OpenFile) (FileUploadControl.OpenFile)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.