Advertisement
locnhse61312

Untitled

Nov 26th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1.   [HttpPost]
  2.         public WrappedJsonResult UploadImage(HttpPostedFileWrapper imageFile)
  3.         {
  4.             if (imageFile == null || imageFile.ContentLength == 0)
  5.             {
  6.                 return new WrappedJsonResult
  7.                 {
  8.                     Data = new
  9.                     {
  10.                         IsValid = false,
  11.                         Message = "No file was uploaded.",
  12.                         ImagePath = string.Empty
  13.                     }
  14.                 };
  15.             }
  16.  
  17.             var fileName = String.Format("{0}.jpg", Guid.NewGuid().ToString());
  18.             var imagePath = Path.Combine(Server.MapPath(Url.Content("~/Content/imgs/product")), fileName);
  19.  
  20.             imageFile.SaveAs(imagePath);
  21.  
  22.             return new WrappedJsonResult
  23.             {
  24.                 Data = new
  25.                 {
  26.                     IsValid = true,
  27.                     Message = string.Empty,
  28.                     ImagePath = Url.Content(String.Format("~/Content/imgs/product/{0}", fileName))
  29.                 }
  30.             };
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement