How to save multiple files at the same time.
I tried the following but its nit working.
- IFormFile file = document.DocumentNameOne;
- IFormFile file2 = document.DocumentNameTwo;
- IFormFile file3 = document.DocumentNameThree;
-
- var webRoot = _env.WebRootPath;
- var path = Path.Combine(
- Directory.GetCurrentDirectory(), webRoot + "/Documents/",
- file.FileName);
- var pathTwo= Path.Combine(
- Directory.GetCurrentDirectory(), webRoot + "/Documents/",
- file.FileName);
- var pathThree = Path.Combine(
- Directory.GetCurrentDirectory(), webRoot + "/Documents/",
- file.FileName);
- using (var stream = new FileStream(pathTwo, FileMode.Create))
- {
- file.CopyTo(stream);
- stream.Close();
- }
- using (var stream1 = new FileStream(pathThree, FileMode.Create))
- {
- stream1.Position = 0;
- file2.CopyTo(stream1);
- }
- using (var stream2 = new FileStream(path, FileMode.Create))
- {
- stream2.Position = 0;
- file3.CopyTo(stream2);
- }