您的位置:程序门 -> .net技术 -> asp.net



紧急求助!在线等!问题解决马上给分。关于多文件上传问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


紧急求助!在线等!问题解决马上给分。关于多文件上传问题[已结贴,结贴人:windstore]
发表于:2007-08-15 18:15:30 楼主
我用js在前台页面动态添加多个 <input   type= "file ">   为什么在cs页面只能获取第一个file呢?

前台代码如下:
<body>
        <form   id= "form1 "   method= "post "   enctype= "multipart/form-data "   runat= "server ">
        <div>
    <table   width= "319 "   height= "38 "   border= "0 "   cellpadding= "0 "   cellspacing= "0 ">
        <tr>
            <td   height= "32 ">
      <label> <a> 添加文件 </a> </label>          
            </td>
            <td   height= "32 "   id= "td1 ">
              <input   type= "file "   name= "file0 "   id= "file0 "   style= "z-index=-1 "   onchange= "javascript:onchangefile() "/>      
            </td>
        </tr>
    </table>
    </form>
</body>

cs页面代码:
    protected   void   page_load(object   sender,   eventargs   e)
        {
                if   (!ispostback)
                {  
                        ajaxpro.utility.registertypeforajax(typeof(ajax_commonfileupload));
                }
                if   (ispostback)
                {
                        upload();

                }
        }
        protected   void   upload()
        {
                string[]   sdr   =   request.files.allkeys;
                foreach   (string   str   in   sdr)
                {
                        response.write(str+ " <br> ");
                }
                httpfilecollection   files   =   httpcontext.current.request.files;
                response.write(files.count);
        }

js代码如下:
  var   td=document.getelementbyid( "td1 ");
number+=1;
td.innerhtml+= " <input   type=\ "file\ "   id=\ "file "+number+ "\ "   onchange= 'javascript:onchangefile() '> ";
发表于:2007-08-15 18:16:401楼 得分:0
response.write(files.count);   总是1
    response.write(str+ " <br> ");   总是file0   也就是不是动态添加的那个file
发表于:2007-08-15 18:24:142楼 得分:50
不用控件也可以

用html   file

后台循环一下

for(int   i=0;i <request.postfiles.length;i++){
    reqeust.postfiles[i].saveas()
}

拼写纯属胡写   基本就这个意思   肯定能实现的
发表于:2007-08-15 18:25:413楼 得分:50
js
添加的时候

要给每个file添加不同的name   否则可能只有1个
发表于:2007-08-15 18:30:454楼 得分:0
我晕。。。果然是这个问题。。。我没有添加name属性。。难道光有id还不能识别么?   谢谢foyuan(暴走零零漆),我搞了一下午快崩溃拉。。。。

搞定了


快速检索

最新资讯
热门点击