EasyUI上传文件C#后台接收文件

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值