Example #1
0
 public async Task <IActionResult> GetFileAsync(string fileName)
 {
     byte[] buffer = _fileBusiness.GetFile(fileName);
     if (buffer != null)
     {
         HttpContext.Response.ContentType = $"application/{Path.GetExtension(fileName).Replace(".", "")}";
         HttpContext.Response.Headers.Add("content-length", buffer.Length.ToString());
         await HttpContext.Response.Body.WriteAsync(buffer, 0, buffer.Length);
     }
     return(new ContentResult());
 }
 public ActionResult Get(string fileName)
 {
     try
     {
         var _content = _fileBusiness.GetFile(fileName);
         return(File(_content, "application/octet-stream"));
     }
     catch (Exception ex)
     {
         return(this.ReturnActionResult(ex));
     }
 }
        public IActionResult GetPDFFile()
        {
            var buffer = _fileBusiness.GetFile();

            if (buffer != null)
            {
                HttpContext.Response.ContentType = "application/pdf";
                HttpContext.Response.Headers.Add("content-lenght", buffer.Length.ToString());
                HttpContext.Response.Body.Write(buffer, 0, buffer.Length);
            }

            return(new ContentResult());
        }
Example #4
0
        public async Task <IActionResult> GetFileAsync(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(BadRequest("invalid client request"));
            }

            var file = _business.GetFile(filename);

            if (file == null)
            {
                return(NotFound("File not found"));
            }

            HttpContext.Response.ContentType = $"application/{Path.GetExtension(filename).Replace(".", "")}";
            HttpContext.Response.Headers.Add("content-length", file.Length.ToString());
            await HttpContext.Response.Body.WriteAsync(file, 0, file.Length);

            return(new ContentResult());
        }
        public ActionResult Get()
        {
            var stream = new FileStream(_fileBusiness.GetFile(), FileMode.Open);

            return(File(stream, "application/pdf", $"{DateTime.Now}.pdf"));
        }