ASP.net应用程序从客户端读取数据 [英] ASP.net application read data from client

查看:102
本文介绍了ASP.net应用程序从客户端读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有asp.net应用程序,我想从客户端机器读取数据。数据位于客户端计算机C:\上,但是当我放置路径时,它从服务器路径读取数据。如何让它从客户端机器读取路径?

解决方案

如果你想这样做,你需要用户同意。如果您想在服务器上处理它,那么您可以在那里上传它并处理它并返回用户想要返回的任何内容。对于客户端处理,您可以使用像这样的文件阅读器:



 document.getElementById('  file')。addEventListener(' 更改',readFile, false ); 

函数readFile(evt){
var files = evt.target.files;
var file = files [ 0 ];
var reader = new FileReader();
reader.onload = function(){
console.log( this .result);
}
reader.readAsText(file)
}





但IE浏览器仅支持IE浏览器10和11所以你可能会遇到问题,这里是jsfiddle: http://jsfiddle.net/XRZNX/ [ ^ ]



也有看看这个:

http://stackoverflow.com/questions/750032/reading-file-contents-on-the-client-side-in-javascript-in-various-browsers [ ^


I have asp.net application and I want to read data from client machine. the data is located on client machine C:\ but when I put the path it read data from the server path. How to make it read path from client machine?

解决方案

You would need user consent if you want to do this. If you want to process it on the server then you can upload it there and process it and return user whatever you want to return. For client side processing you can use something like file reader like this:

document.getElementById('file').addEventListener('change', readFile, false);

   function readFile (evt) {
       var files = evt.target.files;
       var file = files[0];
       var reader = new FileReader();
       reader.onload = function() {
         console.log(this.result);
       }
       reader.readAsText(file)
    }



but FileReader is only supported in IE 10 and 11 so you may run into issues there and Here is the jsfiddle: http://jsfiddle.net/XRZNX/[^]

Also have a look at this:
http://stackoverflow.com/questions/750032/reading-file-contents-on-the-client-side-in-javascript-in-various-browsers[^]


这篇关于ASP.net应用程序从客户端读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆