示例#1
0
        public ActionResult UploadScreenshot(int GoodsId)
        {
            HttpFileCollection uploadFille = System.Web.HttpContext.Current.Request.Files;

            for (int i = 0; i < uploadFille.Count; i++)
            {
                string fileName       = uploadFille[i].FileName;
                string fileExt        = System.IO.Path.GetExtension(fileName).ToLower();
                string uploadFileName = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss") + fileExt;
                string directoryPath  = Server.MapPath("/Images/Goods/Screenshots/");
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory("/Images/Goods/Screenshots/");
                }
                string filePath = "/Images/Goods/Screenshots";
                string path     = Request.MapPath(filePath + "/") + uploadFileName;
                uploadFille[i].SaveAs(path);
                goodsService.AddScreenshot(GoodsId, "http://localhost:8000/Screenshots/" + uploadFileName);
            }
            return(Content("上传成功!"));
        }