Exemplo n.º 1
0
        public ActionResult Upload(HttpPostedFileBase file, Sach obj)
        {
            try
            {
                if (file.ContentLength > 0)
                {
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    fileName += "_" + obj.IDSach;
                    fileName += Path.GetExtension(file.FileName);
                    string folderPath = Server.MapPath("~") + @"\images\image";
                    if (!Directory.Exists(folderPath))
                    {
                        Directory.CreateDirectory(folderPath);
                    }
                    string path = Path.Combine(folderPath, fileName);

                    file.SaveAs(path);
                    var dao = new SachDao();
                    dao.Upload(obj.IDSach, fileName);
                }
                return(RedirectToAction("Index"));
            }
            catch (System.Exception ex)
            {
                return(View(obj));
            }
        }