asp.net多个文件上传

时间:2009-03-02    点击:1593   

<script>

    function addFileControl()
    {
     var str = '<input type="file" runat="server" style="width:80%" /><br>'
     document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
    }

</script>


<FORM id=form1 encType=multipart/form-data runat="server">

<p id="FileCollection"><input type="file" runat="server" style="width:80%"/> <a href="javascript:;" onclick="addFileControl()">+</a> </p>

</FORM>

 

        ///////////////////////////////////////////////////////////////////////////////

        System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
      
        int fileCount;
        int filecount = files.Count;

        string rnd1;
        string mPath1 = Server.MapPath("../../pimages/");
        string img1;


        for (fileCount = 1; fileCount < files.Count; fileCount++)
        {
           
            //定义访问客户端上传文件的对象
            System.Web.HttpPostedFile postedFile = files[fileCount];

            string fileName, fileExtension;

            //取得上传得文件名
            fileName = System.IO.Path.GetFileName(postedFile.FileName);

            if (fileName != String.Empty)
            {
                rnd1 = "";
                rnd1 = sqldata.rndNum() + fileCount.ToString(); //随机文件名

                //取得文件的扩展名
                fileExtension = System.IO.Path.GetExtension(fileName);
              
                postedFile.SaveAs(mPath1 + rnd1 + fileExtension);              

                img1 = rnd1 + fileExtension;

             }
        }

        ////////////////////////////////////////////////////////////////////////////////

JavaScript时钟
显示农历日历(4)
asp大数据存储过程分页全部代码
asp.net单个文件上传
asp.net多个文件上传
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 All Rights Reserved