Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public static string uploadPhoto(HttpPostedFile file, string folder)
  2. {
  3. string path = string.Empty;
  4. string pic = string.Empty;
  5.  
  6. if (file != null)
  7. {
  8. pic = Path.GetFileName(file.FileName);
  9. path = Path.Combine(HttpContext.Current.Server.MapPath(folder), pic);
  10. file.SaveAs(path);
  11.  
  12. using (MemoryStream ms = new MemoryStream())
  13. {
  14. file.InputStream.CopyTo(ms);
  15. byte[] array = ms.GetBuffer();
  16. }
  17. }
  18.  
  19. return pic;
  20. }
  21.  
  22. string pic = string.Empty;
  23. string folder = "~/Content/imagenes";
  24.  
  25.  
  26. if (view.imageFile != null)
  27. {
  28. pic = FilesHelpers.uploadPhoto(view.imageFile, folder);
  29. pic = string.Format("{0}/{1}", folder, pic);
  30. }
  31.  
  32. var factura = toFactura(view);
  33. factura.foto = pic;
  34.  
  35. db.factura.Add(factura);
  36. db.SaveChanges();
  37.  
  38. return RedirectToAction("Index");
  39.  
  40. }
  41.  
  42. ViewBag.fichaCamion = new SelectList(db.camion, "id", "camion1", view.fichaCamion);
  43. ViewBag.cliente = new SelectList(db.cliente, "id", "compania", view.cliente1);
  44. return View(view);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement