日期:2014-05-17 浏览次数:20431 次
//ajax方式提交到FileImport.ashx function 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 } }