public IActionResult DownloadFile(long productID) { // Will send the productID to service & repository, where it will get the path where the file is // from the database. In the service will get the pdf file and convert to FileStream and send back. Tuple <string, FileStream, bool> stream = service.GetSpecificationFilePdf(productID); if (stream.Item3 == false || stream.Item2 == null) { //return NotFound(); return(new NotFoundResult()); } // Will send the PDF stream to the view, changing the name!!! (security reasons) // In this way no path is send to or from the view! return(new FileStreamResult(stream.Item2, "application/pdf")); // FileContentResult - use it when you have a byte array you would like to return as a file // FileStreamResult - you have a stream open, you want to return it's content as a file //// example how to send the PDF file so that user can save it! //var filePath = "D:\\PortOfAntwerpAppAssets\\PortOfAntwerpAppAssets\\wwwroot\\hardwarePdf\\Port of Antwerp - ERD.pdf"; //byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); //string fileName = "myfile.pdf"; //return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName); }