由于要一次上传多个文件,而且文件数量不定,所以<input type='file'/>是由客户端动态生成的,那么如何保存这些html的file到服务器上?

解决方案 »

  1.   

    以下即可。private void btnSend_Click(object sender, System.EventArgs e)
    {
    StringBuilder sb = new StringBuilder(); int attCount = 0;
    string filePath = "";
    for(int i=0; i< Request.Files.Count; i++)
    {
    if(Request.Files[i].ContentLength > 0)
    {
    filePath = Request.Files[i].FileName;
    sb.Append("Files" + attCount++ + ": " + filePath + "<br>");
    int n = filePath.LastIndexOf("\\");
    Request.Files[0].SaveAs(Server.MapPath("./") + filePath.Substring(n+1));
    }
    } sb.Insert(0, "you upload " + attCount + " files.<br>");
    Response.Write(sb.ToString());
    }