Guest User

Untitled

a guest
Feb 12th, 2020
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [HttpPost]
  2. public async Task<IActionResult> Create(Venue v)
  3. {
  4. var files = HttpContext.Request.Form.Files;
  5. foreach (var Image in files)
  6. {
  7. if (Image != null && Image.Length > 0)
  8. {
  9. var file = Image;
  10.  
  11. var uploads = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/venue");
  12. if (file.Length > 0)
  13. {
  14. var fileName = ContentDispositionHeaderValue.Parse
  15. (file.ContentDisposition).FileName.Trim('"');
  16. using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
  17. {
  18. await file.CopyToAsync(fileStream);
  19.  
  20. v.Image = v.Image + ";" + file.FileName;
  21. }
  22. }
  23. }
  24. }
  25.  
  26. v.UserName = GetUserName(_userManager);
  27. _context.Venues.Add(v);
  28. _context.SaveChanges();
  29. return RedirectToAction(nameof(Index));
  30. }
RAW Paste Data