Controller again for the Http Post after click on the submit button
privatereadonlyIHostingEnvironmenthostingEnvironment;privateStringmyPath;publicUploadController(IConfiguration configuration,IJSRuntime js,IHostingEnvironment environment){_server=configuration;this.js=js;hostingEnvironment=environment;myPath=Path.Combine(hostingEnvironment.WebRootPath,"../../tms_doc");}[HttpPost]publicIActionResultUpload(UploadModelmodel){//var file = model.MyFile;//String SavePath = Path.Combine(Directory.GetCurrentDirectory(),"wwwroot/doc",model.MyFile.FileName);//var uploads = Path.Combine(hostingEnvironment.WebRootPath,"doc");//String SavePath = Path.Combine(uploads, taskname + "_" + model.MyFile.FileName);StringSavePath=Path.Combine(myPath,taskname+"_"+model.MyFile.FileName);using(varstream=newFileStream(SavePath,FileMode.Create)){model.MyFile.CopyTo(stream);}//you have to close the stream otherwise you will get the file in use error in download processstream.Close();returnView();}
[HttpGet("download")]publicIActionResultDownload(StringfileName){//Build the File Path//String ReadPath = Path.Combine(Directory.GetCurrentDirectory(), "doc", fileName);StringReadPath=Path.Combine(myPath,fileName);/* //Read the File data into Byte Array byte[] bytes = System.IO.File.ReadAllBytes(ReadPath); //Send the File to Download return File(bytes, "application/octet-stream", fileName); */varnet=newSystem.Net.WebClient();vardata=net.DownloadData(ReadPath);varcontent=newSystem.IO.MemoryStream(data);returnFile(content,"application/octet-stream",fileName);}