HTML
<div id="editfile" class="easyui-dialog" iconcls="icon icon-edit" buttons="#dlg-buttons-file"
closed="true" modal="true" title="文件上传" style="width: 600px; height: 430px; padding: 5px">
<form id="form_file" method="post" enctype="multipart/form-data">
<div id="Div2"> <legend>选择文件:</legend>
<h2 style="background-color: #f1f1f1; margin-bottom: 10px; font-size: 12px; color: #666; font-weight: normal; line-height: 30px; height: 30px;"> *选择模板文件</h2>
<input type="file" class="easyui-filebox" id="file_upload1" name="file_upload1" style="width:300px" />
</div>
</form>
<div id="dlg-buttons-file">
<table cellpadding="0" cellspacing="0" style="width: 100%">
<tr>
<td style="text-align: right">
<a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="editfileS();">上传</a><a
href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="$('#editfile').dialog('close'); return false;">
取消</a>
</td>
</tr>
</table>
</div>
</div>
js代码
function editfileS() {
if (document.getElementsByName("file_upload1")[0].files[0] != null) {
//console.log(FileInfoNo)
$("#form_file").form("submit", {
url: '../ashx/upload/upload.ashx?action=editfile',
onSubmit: function (param) {
return $(this).form('validate');
},
success: function (jsonResult) {
$.show_warning_inframe(jsonResult, 'success');
$('#editfile').dialog('close');
}
});
} else {
$.show_warning_inframe("请添加要修改的文件!", 'success');
}
}
C#后台
HttpPostedFile file = context.Request.Files[0];
file.FileName
file.ContentLength
FileSize = Decimal.Round(Convert.ToDecimal(file.ContentLength) / 1024, 2)
通过HttpPostedFile 获取到file,基本上就是这几种
如果想将整个文件存入数据库,必须要把 filename、ContentLength、FileSize一并存入,以SqlServer为例,要将ContentLength存入表字段类型为image