解决方案 »

  1.   

    创建目录:
    Directory.CreateDirectory文件名的问题在另一个帖子中回答你了。
      

  2.   

    前台:   <asp:FileUpload ID="FileUpload_Upload" runat="server" CssClass="textbox" />
                &nbsp;<asp:Button ID="Button_Uploadfile" runat="server"
                    Text="Upload" CssClass="textbox" style="cursor:hand" 
                    onclick="Button_Uploadfile_Click" /> 
    后台:
    //没文件夹创建文件夹
     public void FolderPath(string pathStr)
        {
            if (!Directory.Exists(pathStr))
            {
                Directory.CreateDirectory(pathStr);
            }
        }
    //按钮触发
     protected void Button_Uploadfile_Click(object sender, EventArgs e)
        {
            string ServerPath = System.Web.HttpContext.Current.Request.MapPath("upload/"+DateTime.Now.ToString("yyyyMMdd"));
            if (!string.IsNullOrEmpty(this.FileUpload_Upload.PostedFile.FileName))
            {
                FolderPath(ServerPath);
     string Sion = Path.GetExtension(this.FileUpload_Upload.FileName);
                string file = Path.GetFileNameWithoutExtension(this.FileUpload_Upload.FileName);
                string FileName =file+ DateTime.Now.ToString("yyyyMMddHHmmssFFFFF")+Sion;
                this.FileUpload_Upload.PostedFile.SaveAs(ServerPath + "/" + FileName );
                //Alert("Upload success");
                
            }
            else { 
    //Alert("Please Select File To Upload!");
     }
        }
      

  3.   

                 
                    string timeStamp = DateTime.Now.ToString("yyyyMM");
                    string path = Server.MapPath("/uploadfile/" + timeStamp);
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);
      

  4.   

    string usename = users[0].CUserName.ToString();              //获取用户名
                string randomName = DateTime.Now.ToFileTime().ToString();   //系统当前时间为图片名称
                //string path = Request.MapPath("~/Content/images");    
                HttpPostedFileBase file = Request.Files["fileToUpload"];//获取页面上获取图片内容["fileToUpload"] 是页面上上传图片空间的name
                string pictureName = file.FileName;//上传图片的原名
                string extensionName = System.IO.Path.GetExtension(pictureName);//获取扩展名
                int randomcode = BaseRandom.GetRandom(1000, 9999);                //产生随机数
                string newName = string.IsNullOrEmpty(pictureName.Trim()) ? "" : usename + randomcode + randomName + System.IO.Path.GetExtension(pictureName);                                                                //重命名图片
                    string savePath = HttpContext.Server.MapPath("~/Content/Uploads/img/" + usename);  //原图图片保存位置
                    if (!System.IO.Directory.Exists(savePath))
                    {
                        //如果路径不存在创建新文件夹
                        System.IO.Directory.CreateDirectory(savePath);
                    }
                    file.SaveAs(savePath +'/'+newName);                                                                           //将上传的文件保存到指定的目录。
                     ViewData["messageBox"] = "上传成功";
    ps:这算是很完整的了