上传图片并创建带日期的文件夹

if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files["file"];
                string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads/"+                  DateTime.Now.ToString("yyyyMMdd")+"/"), Path.GetFileName(file.FileName));
                string sPath = Path.Combine(HttpContext.Server.MapPath("../Uploads/"+DateTime.Now.ToString("yyyyMMdd")));
                if (!Directory.Exists(sPath))
                {
                    Directory.CreateDirectory(sPath);
                }
                file.SaveAs(filePath);
                goIn.GoodsPhoto = "/Uploads/"+DateTime.Now.ToString("yyyyMMdd")+"/" + Path.GetFileName(file.FileName);
            }
            using (GoodsInfoManage goInMan=new GoodsInfoManage ())
            {
                result = goInMan.AddGoods(goIn);
            }

posted on 2016-11-10 17:55  焦会锋  阅读(293)  评论(0编辑  收藏  举报

导航