Public classFilecontroller:controller {/// <summary> ///unlike ASP. NET WebForm and ASP. NET MVC, get the path of the project by injecting/// </summary>private ihostingenvironment _hostenv; public Filecontroller (Ihostingenvironment env) {_hostenv = env;//Other services} Publi C Iactionresult Index () {return View ();}/// <summary> ///mode one output text file/// </summary> /// <returns></returns>Public Iactionresult DownloadFile1 () {var buffer = Encoding.UTF8.GetBytes ("ASP. NET core download file"); return file (Buffer, "Text/plain", "file.txt"); } /// <summary> ///mode two output text file/// </summary> /// <returns></returns>Public Iactionresult DownloadFile2 () {var stream = new MemoryStream (); var streamWriter = new StreamWriter (stream); StreamWriter.Write ("{\" content\ ": \" ASP. NET Core download File\ "}"); StreamWriter.Flush (); Stream. Seek (0, Seekorigin.begin); Return File (Stream, "Text/plain", "File.json"); } /// <summary> ///mode three output picture file/// </summary> /// <returns></returns>Public Iactionresult DownloadFile3 () {var path = Path.Combine (_hostenv.contentrootpath, "UploadFile", " Netcore5.png "); var fileextensionname = path.getextension (Path); return PhysicalFile (Path, "Image/png", $ "{DateTime.Now.ToString (" Yyyymmddhhmmss ")}.{ Fileextensionname} "); } /// <summary> ///multiple file uploads/// </summary> /// <param name= "Files" >name of File upload</param> /// <returns></returns>Public Iactionresult UploadFile (IList<IFormFile>files) {if (Files! = null) {//handles multi-file foreach (var file in files) {////If file processing is required, you can filter by file extension var fileextensionname = Path.getex Tension (file. FileName). Substring (1); var Savefilepath = Path.Combine (_hostenv.contentrootpath, "UploadFile", $ "{DateTime.Now.ToString (" Yyyymmddhhmmss ")} . {fileextensionname} "); var stream = new FileStream (Savefilepath, FileMode.Create); ASP. NET core is good for asynchronous support, and if you use async you can use file. Copytoasync method file. CopyTo (stream); } return Ok (); } else {return Ok ();}} }"/file/uploadfile"Enctype="Multipart/form-data"Method="Post"> <input type="file"Name="Files"Multiple/> <input type="Submit"Value="Uploading Files"/> </form> </body> ASP. NET core file upload and download