实现多文件上传 将孟子E章得代码稍微修改了一下
现在的问题是 他的代码只能靠Web按钮的点击事件来实现
我现在想用html控件 想在前台调用后台函数 关键这整个函数必须返回string 类型那么我整个函数该如何返回?
 //多文件上传
        public void FN_UpFiles()
        {
            //遍历File表单元素
            HttpFileCollection files = HttpContext.Current.Request.Files;
            try
            {
                for (int iFile = 0 ; iFile < files.Count ; iFile++)
                {
                    //检查文件扩展名字
                    HttpPostedFile postedFile = files[iFile];
                    string fileName = "";
                    fileName = Path.GetFileName(postedFile.FileName);
                    if (fileName != "")
                    {
                        try
                        {
                            string strpath = System.Web.HttpContext.Current.Request.MapPath("~/ResourcesFolder/") + fileName;
                            if (System.IO.File.Exists(strpath))
                            {
                                Response.Write("已经存在文件:" + fileName + "<br>");
                            }
                            else
                            {
                                try
                                {
                                    NRModel.File model = new NRModel.File();
                                    NRBLL.File bf = new NRBLL.File();
                                    Guid guid1 = Guid.NewGuid();
                                    Guid guid2 = Guid.NewGuid();
                                    Guid guid3 = Guid.NewGuid();
                                    Guid guid4 = Guid.NewGuid();
                                    model.Fileid = guid1;
                                    model.Folderid = guid2;
                                    model.Filepath = strpath;
                                    model.FileNam = fileName.ToString();
                                    model.FileSize = postedFile.ContentLength;
                                    model.Decription = this.decrition.Value;
                                    model.CreateOn = DateTime.Now;
                                    model.CreateBy = guid3;
                                    model.ModefyBy = guid4;
                                    if (bf.FN_AddNewRes(model) > 0)
                                    {
                                        postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("~/ResourcesFolder/") + fileName);
                                        Page.RegisterStartupScript("提示", "<script language='javascript'>alert('上传成功!')</script>");
                                        Response.Write("<script language='javascript'>self.opener.location.reload();</script>");
                                        Response.Write("<script language='javascript'>window.close();</script>");
                                    }
                                }
                                catch (Exception ex)
                                {                                    Response.Write(ex.ToString());
                                }                            }                        }
                        catch (Exception ex)
                        {
                            Response.Write(ex.ToString());
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }

解决方案 »

  1.   

    关键是第一句代码需要遍历前台页面中的file表单元素 如果用ajax怎么去遍历当前页面前台的file?
      

  2.   


    服务器控件,只是 asp.net 给你包装好的html控件
      

  3.   

    我知道 可是公司不让用web控件- - 都得替换成HTML的 我现在的想法就是在JS中调用后台的函数 但是查了百度和谷歌 需要返回类型是string
      

  4.   

    http://www.open-open.com/ajax/Upload.htm
      

  5.   

    swfupload,这个控件好用,批量上传,有进度条。swfupload demo
      

  6.   

    public string FN_UpFiles()jquery 批量上传插件Uploadify
      

  7.   

    定义成返回类型string 我知道 那么我这段函数返回的时候 return ?
      

  8.   

    设置form 的 enctype="application/x-www-form-urlencoded"
    action="uploadfile.aspx"
    获取所有上传文件 Request.Files
      

  9.   

    \]
    你的意思是用submit表单提交的方式?