ASP.NET 如何实现读取客户端C盘的某个文本文件?
ASP.NET 如何实现读取客户端C盘的某个指定文本文件? 路径指定的
[解决办法]
web模式的获取不到客户端文件的,浏览器就是这样设计的
[解决办法]
所以只能用上传控件上传到服务器处理
[解决办法]
除非是winform程序,在web中是不可能实现的。要不没安全可言
[解决办法]
你怎么知道客户端有C盘?
[解决办法]
获取文件名 然后通过流的方式读取 比如下面的一个导入txt文件的例子
- JScript code
//ajax方式提交到FileImport.ashxfunction upLoadFile() { if ($("#<%=File1.ClientID%>").val() != "") { var id = $("#<%=ChannelID.ClientID%>").val(); var options = { type: "POST", url: 'FileImport.ashx?action=' + id, beforeSubmit: showRequest, success: showResponse }; $('#myForm').ajaxSubmit(options); } else { alert("请选择需要导入的节目单文件!"); }}//FileImport.ashx读取txt文件内容HttpFileCollection files = context.Request.Files;if (files.Count > 0){ string id=context.Request.QueryString["action"]; HttpPostedFile file = files[0]; int FileLen = file.ContentLength; byte[] input = new byte[FileLen]; System.IO.Stream uploadStream = file.InputStream; uploadStream.Read(input, 0, FileLen); uploadStream.Position = 0; System.IO.StreamReader sr = new System.IO.StreamReader(uploadStream, Encoding.GetEncoding("gb2312")); string line; while ((line = sr.ReadLine()) != null) { //domething }}