<script type="text/javascript" src="jquery.uploadify.min.js"></script
<link rel="Stylesheet" href="uploadify.css" type="text/css" />
<script type="text/javascript"> $(document).ready(function () { $('#uploadify').uploadify({ 'swf': 'uploadify.swf', 'buttonText': 'Loading', 'uploader': 'Uploadhandler.ashx', 'queueID': 'fileQueue', 'queueSizeLimit': 10, 'auto': false, 'multi': false, 'removeCompleted': true, 'fileSizeLimit': '100MB', 'fileTypeDesc': 'Excel文件', 'fileTypeExts': '*.xls', 'onUploadSuccess': function (file, data, response) { layer.closeAll(); layer.open({ type: 1, skin: 'layui-layer-rim', //加上边框 area: ['520px', '340px'], //宽高 content: '<div>File Name:' + file.name + data + '</div>' }); }, 'onUploadError': function (event, queueId, fileObj, errorObj) { layer.closeAll(); }, 'onUploadStart': function (file) { $("#uploadify").uploadify("settings", "formData", { 'ddlregion': $('#ddlRegionSearch').val() }); //动态参数 } }); $('#supload').click(function supload() { $('#uploadify').uploadify('upload', '*'); }); }); </script>
<div> <input type="file" name="uploadify" id="uploadify" /><button id="supload" class="btn">开始上传</button> </div> <div id="fileQueue"></div>
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = context.Request.MapPath("/Upload/Files/"); try { if (file != null) { string fileName = uploadPath + file.FileName; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } //将文件上传至服务器 file.SaveAs(fileName); context.Response.Write("<br>The import is complete!"); } else { context.Response.Write("<br>File loading failure!"); return; } } catch (Exception ex) { context.Response.Write("<br>Exception: " + ex.Message); } }