zoukankan      html  css  js  c++  java
  • Extjs+C# 文件上传

    var ImportPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            frame: false,

       // 注意formPanel里面的fileUpload一定要打开
            fileUpload: true,
            id: 'ImportPanel',
            url: 'Excel.aspx?ac=Import',
            items: [{
                xtype: 'textfield',

        // 注意要有以下字段
                inputType: 'file',
                fieldLabel: '请选择导入文件',
                id: 'stationFile',
                150,
                allowBlank: false
            }]
        });
    var ImportWinFrom = new Ext.Window({
        layout: 'fit',
        360,
        height: 100,
        closeAction: 'hide',
        title:'导入数据',
        plain: true,
        items: ImportPanel,
        buttons: [{
            text: '提交',
            formPanel:this.ImportPanel,
            handler: function() {
                this.formPanel.form.submit({
                    success: function(form, action) {
                        Ext.Msg.alert("导入成功", action.result.msg);
                        mportWinFrom.hide();
                    },
                    scope: this,
                    failure: function(form, action) {
                        Ext.Msg.alert("导入失败", action.result.msg);
                        this.parent.SuperSearchWinForm.hide();
                    }
                });
            }
        }, {
            text: '取消',
            handler: function() {
                ImportWinFrom.hide();
            }
        }]
    });

    C# 代码

    public void UploadFile()

    {

       // 接收Http发送过来的文件

         HttpFileCollection files = HttpContext.Current.Request.Files;
             HttpPostedFile postedFile = files[0];
             Hashtable hash = new Hashtable();
             JavaScriptSerializer adapter = new JavaScriptSerializer();
                
             string url = "uploadfile/excel/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
             try
             {
                 postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(url));
             }
             catch
             {
                 hash.Add("success",false);
                 hash.Add("msg", "上传附件失败!");
                 MyResponse(hash);
             }

    }

  • 相关阅读:
    Http Requests for PHP
    关于ORA-00979 不是 GROUP BY 表达式错误的解释
    boke例子: freermarker:在使用ajax传递json数据的时候多出冒号
    boke练习: springboot整合springSecurity出现的问题,传递csrf
    boke练习: springboot整合springSecurity出现的问题,post,delete,put无法使用
    feign三:覆写feign的默认配置及feign的日志
    boke练习: spring boot: security post数据时,要么关闭crst,要么添加隐藏域
    boke练习: freemarker对空变量报错 (classic_compatible设置true,解决报空错误)
    mysql查询、子查询、连接查询
    MySQL Group By 实例讲解(二)
  • 原文地址:https://www.cnblogs.com/oftenlin/p/2676276.html
Copyright © 2011-2022 走看看