代码有点乱
主要是这样的
<script language="JavaScript">
    function addFile()
    {
     var str = '<INPUT type="file" runat="server" size="50" NAME="File" id ="myId">'
     document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
    }
</script><P id="MyFile" align="center"><INPUT type="file" size="50" name="File"></p>
<P><input onclick=addFile() type=button value=增加(Add)> 
</P>用一个button用JavaScript生成fileInput

解决方案 »

  1.   

    give your control a name, different for each <input type=file> preferablyon the server side, go through Request.Files collection, each one of them is a HttpPostedFile instance
      

  2.   

    写成
    var str = '<INPUT type="file" size="50">'
    服务端:
    //上传文件的集合
    System.Web.HttpFileCollection files = system.Web.HttpContext.Current.Request.Files;
    //共上传的文件个数
    int iFile = files.Count;
    //定义一个arraylist来存放附件
    ArrayList arrayFujian = new ArrayList();
    for(int i = 0; i < iFile; i ++)
    {
    HttpPostedFile file = files[i];
    string strKey = files.Keys[i].ToString();
    //取得文件详细信息
    string strContent = "";
    string strFileName = "";
    string strFileExt = "";
    string strFileType = "";
    //
    if(GetFile(file, ref strContent, ref strFileName, ref strFileExt, ref strFileType) == 1)
    {
    if(strKey == "Fujian")
    {
    Wenjian wj = new Wenjian();
    wj.Bianma = "base64";
    wj.Mingcheng = strFileName;
    wj.Leixing = strFileType;
    wj.Shuoming = strFileExt;
    wj.Shuju = strContent;
    arrayFujian.Add(wj);
    }
    }
    //
    }
    /// <summary>
    /// 从HttpPostedFile对象中取得其详细信息
    /// </summary>
    /// <param name="file">上传的文件对象</param>
    /// <param name="strContent">文件的base64字串</param>
    /// <param name="strMingcheng">文件名</param>
    /// <param name="strExt">文件扩展名</param>
    /// <param name="strLeixing">类型说明</param>
    /// <returns>int(1正确)</returns>
    private int GetFile(HttpPostedFile file, ref string strContent, ref string strMingcheng, ref string strExt, ref string strLeixing)
    {
    if(file != null)
    {
    try
    {
    Stream stream = file.InputStream;
    string strFile = file.FileName;
    string strFileName = Path.GetFileName(strFile); //strFile.Substring(strFile.LastIndexOf("\\") + 1);
    strExt = Path.GetExtension(strFile);  //strFileName.Substring(strFileName.LastIndexOf(".") + 1);
    strMingcheng = strFileName;
    if(file.ContentLength == 0)
    {
    return -1;
    }
    strLeixing = file.ContentType;
    byte[] byteTemp = new byte[stream.Length];
    stream.Seek(0, SeekOrigin.Begin);
    stream.Read(byteTemp, 0, byteTemp.Length);
    stream.Close();
    strContent = Convert.ToBase64String(byteTemp);
    return 1;
    }
    catch
    {
    return -1;
    }
    }
    else
    return -1;
    }
      

  3.   

    如果客户端的File控件有不同的ID的话,就可以像上面的代码一样, 通过strKey来访问某种类型ID的文件
      

  4.   

    to saucer:
    是用
    Request.Files[fileInputName]吗?
      

  5.   

    可能问题没有说清楚:我要动态生成上传文件的fileInput
    但生成的fileInput上传的文件是有不同的类型的,在上传前通过选择类别(如论文,规定等)。因为文件数目确定,要用动态法生成。但生成用的javascript函数是同一的,提交后如何区别他们呢?
      

  6.   

    我是自己写的ActiveX 按照它的MIME格式编码提交给aspx,实现多文件上传的。