日期:2014-05-17  浏览次数:20395 次

为何获取不到FileUpload的文件名
这是前台“确认上传”按钮按下触发的后台行为代码:

protected void UpImgs(object sender, EventArgs e)
    {
        for (int j = 0; j < this.Controls.Count; j++)
        {
            foreach (object o in Page.Controls[j].Controls)
            {
                if (o is FileUpload)
                {
                    FileUpload fu = (System.Web.UI.WebControls.FileUpload)o;
                    string fileName = System.IO.Path.GetFileName(fu.FileName);
                    string path = "/admin/imgs";
                    string localPath = Server.MapPath(Request.ApplicationPath + path);
                    string fullPath = localPath + "\\" + fileName;
                    Response.Write(fullPath);
                }
            }
        }
  }
----------------------------------------------------


如图,点了这个按钮后,只显示了路径,没有显示最后的文件名,而且就是如图选了2个文件,它也只显示一行Response.Write而已,按理说我遍历了有文件的FileUpload,应该是输出两句啊,请问是为何呢?求指教谢谢

------解决方案--------------------
     HttpFileCollection files = HttpContext.Current.Request.Files;
        for (int i = 0; i < files.Count; i++)
        {
          string fileName = files[i].FileName
            if (!string.IsNullOrEmpty(fileName))
            {
   Response.Write(formName);
             }
        }


这么写!
------解决方案--------------------
上传多个文件示例:http://blog.csdn.net/dalmeeme/article/details/7429198