osyris zosar

osyris zosar

  • NA
  • 289
  • 23.6k

File.CopyTo sends file to complete different directory

Apr 12 2021 6:50 AM
I am trying to upload a image using IFormFile using the following code:
  1. //IWebHostEnvironment _webHost  
  2.   
  3. string FileName = Path.GetTempFileName() + "_" + productsI.HeaderImage.FileName;  
  4. string FilePath4 = Path.Combine(_webHost.WebRootPath, "Images""HeaderImage", FileName);  
  5.   
  6. using (var stream = System.IO.File.Create(FilePath4))  
  7. {  
  8.     await productsI.HeaderImage.CopyToAsync(stream);  
  9. }  
 It should send it to "C:\Users\user\Desktop\Asp_net_core\Webshop\wwwroot\Images\HeaderImage"
instead of that it is sending it to:  C:\Users\user\AppData\Local\Temp
 
That file path is not even close to what I have programmed C# to do

Answers (4)