FineUI 官方论坛

标题: 文件上传,AspNet 后面怎么写? [打印本页]

作者: extnet    时间: 2012-11-2 03:16
标题: 文件上传,AspNet 后面怎么写?

这里是前台的js,从网上找的.
var win = new Ext.Window({        title: '文件上传',        width: 400,        height: 100,        minWidth: 300,        minHeight: 100,        layout: 'fit',        plain: true,        bodyStyle: 'padding:5px;',        buttonAlign: 'center',        items: form,        buttons: [{            text: '上传',            handler: function () {                if (form.form.isValid()) {                    if (Ext.getCmp('userfile').getValue() == '') {                        Ext.Msg.alert('错误', '请选择你要上传的文件');                        return;                    }                    Ext.MessageBox.show({                        title: '请等待',                        msg: '文件正在上传...',                        progressText: '',                        width: 300,                        progress: true,                        closable: false,                        animEl: 'loding'                    });                    form.getForm().submit({                        url: 'Action/UpdateLoad',                        method: 'POST',                        success: function (form, action) {                            Ext.Msg.alert('Message',            action.result.success);                            win.close();                        },                        failure: function () {                            Ext.Msg.alert('Error',            'File upload failure.');                        }                    })                }            }        }, {            text: '关闭',            handler: function () {                win.close();            }        }]    });    win.show();

需要后台post 到接受服务,这个怎么写?


我用的Ext.Net1.5 ,里面GridPanel 不支持 uploadfield 用ajax 方法直接响应 cell command. 但接收不会.

有人能解答下么?


作者: extnet    时间: 2012-11-3 01:40
已经解决
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Ext.Net;

namespace erp_asp_net.WebPage.Sales
{

    public class result
    {
        public bool success;
        public string msg;
    }
    /// <summary>
    /// FileResponse 的摘要说明
    /// </summary>
    public class FileResponse : IHttpHandler
    {

        // extjs submit()
        //would process the following server response for a successful submission:

        //{
        //    "success":true, // note this is Boolean, not string
        //    "msg":"Consignment updated"
        //}

        //and the following server response for a failed submission:

        //{
        //    "success":false, // note this is Boolean, not string
        //    "msg":"You do not have permission to perform this operation"
        //}
        public void ProcessRequest(HttpContext context)
        {
            result res = new result();
            context.Response.ContentType = "text/html";
            if (context.Request.Files.Count > 0)
            {
                res.success = true;
                res.msg = "成功上传";
                string respone = JSON.Serialize(res);
                string fn = context.Request.Files[0].FileName;
                //int fl = context.Request.Files[0].ContentLength;
                string strPath = context.Server.MapPath("~/") + fn;

                context.Request.Files[0].SaveAs(strPath);
                //StreamReader file = new StreamReader(context.Request.Files[0].InputStream);
                context.Response.Write(respone);
            }
            else
            {
                res.success = false;
                res.msg = "失败";
                string respone = JSON.Serialize(res);
                context.Response.Write(respone);
            }
            
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}




欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/) Powered by Discuz! X3.4