Thamsanqa Ngcongwane

Thamsanqa Ngcongwane

  • NA
  • 184
  • 25.1k

How To Save Multiple Files

Oct 28 2019 7:35 AM
How to save multiple files at the same time.
I tried the following but its nit working.
  1. IFormFile file = document.DocumentNameOne;  
  2. IFormFile file2 = document.DocumentNameTwo;  
  3. IFormFile file3 = document.DocumentNameThree;  
  4.    
  5. var webRoot = _env.WebRootPath;  
  6. var path = Path.Combine(  
  7. Directory.GetCurrentDirectory(), webRoot + "/Documents/",  
  8. file.FileName);  
  9. var pathTwo= Path.Combine(  
  10. Directory.GetCurrentDirectory(), webRoot + "/Documents/",  
  11. file.FileName);  
  12. var pathThree = Path.Combine(  
  13. Directory.GetCurrentDirectory(), webRoot + "/Documents/",  
  14. file.FileName);  
  15. using (var stream = new FileStream(pathTwo, FileMode.Create))  
  16. {  
  17. file.CopyTo(stream);  
  18. stream.Close();  
  19. }  
  20. using (var stream1 = new FileStream(pathThree, FileMode.Create))  
  21. {  
  22. stream1.Position = 0;  
  23. file2.CopyTo(stream1);  
  24. }  
  25. using (var stream2 = new FileStream(path, FileMode.Create))  
  26. {  
  27. stream2.Position = 0;  
  28. file3.CopyTo(stream2);  
  29. }  

Answers (4)