那你就在pageload的时候获取日期嘛,然后判断是否存在,不存在就创建,上传的时候也就根据日期选择文件夹就OK了,
if (!Directory.Exists(imgpath))
Directory.CreateDirectory(imgpath);

解决方案 »

  1.   

      if (FileUpload1.PostedFile.FileName != "")
                {
                    string uploadName = FileUpload1.PostedFile.FileName;//获取待上传图片的完整路径,包括文件名 
                    //string uploadName = InputFile.PostedFile.FileName; 
                    string pictureName = "";        //上传后的图片名,以当前时间为文件名,确保文件名没有重复 
                    int idx = uploadName.LastIndexOf(".");
                    string suffix = uploadName.Substring(idx);       //获得上传的图片的后缀名 
                    Random rand = new Random();
                    int c = rand.Next(1000, 9999);
                    pictureName = DateTime.Now.Ticks.ToString() + "_" + c + suffix;
                    string Files_Date = DateTime.Now.ToString("yyyyMMdd");
                    string path = Server.MapPath("image/" + Files_Date + "/");
                    //string path2 = Server.MapPath("~/image/small/" + Files_Date + "/");
                    if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                    //if (!Directory.Exists(path2)) Directory.CreateDirectory(path2);
                    FileUpload1.PostedFile.SaveAs(path + pictureName);
                    string webpath = Server.MapPath("image/" + Files_Date + "/" + pictureName);
                    //string webpath2 = Server.MapPath("~/image/small/" + Files_Date + "/" + pictureName);
                    //MakeThumbnail(webpath, webpath2, 130, 130, "Cut");
                    //生成缩略图并存进文件夹                UserEntity ue = new UserEntity();
                    ue.RegistName = this.txt_regist.Text.Trim();
                    ue.RoleName = this.txt_role.Text.Trim();
                    ue.ServerName = this.txt_server.Text.Trim();
                    ue.PicPath = "image/" + Files_Date + "/" + pictureName;
                    bool result = new UserService().Addinfo(ue);
                    if (result)
                        Response.Write("<script>alert('提交成功');location='toupiao.aspx'</script>");
                    else
                        Response.Write("<script>alert('提交失败');</script>");            }
                else
                {
                    Response.Write("<script>alert('图片不能为空哦');location='javascript:history.go(-1);'</script>");
                }