2

I am trying to return a file content via the ActionResult. However, I cannot find which library the File() functions belong to. So the File(..) is not valid. Which library does the File belong to ? I need to add it. Is it belong to system.web.mvc? but I cannot find File in System.Web.Mvc.

[HttpGet]
        public virtual ActionResult Download(string fileGuid,string fileName)
        {
            Guid guid = new Guid(fileGuid);
            if (store[guid].Ready != 0)
            {
                byte[] data = store[guid].Data as byte[];

                // The File here is not valid, I can't find which library it belong to
                return File(data, "application/vnd.ms-excel",fileName);
            }
            else
            {                   
                return new EmptyResult();
            }
        }
want_to_be_calm
  • 1,477
  • 3
  • 23
  • 41

1 Answers1

2

This may depend on the exact target framework, but: there are a range of public virtual FileContentResult File(...) overloads on Microsoft.AspNetCore.Mvc.ControllerBase which should be available if your controller inherits from that. Alternatively, you can use new FileContentResult(...) directly, from Microsoft.AspNetCore.Mvc - all in Microsoft.AspNetCore.Mvc.Core.dll.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900