Download file of any type in Asp.Net MVC using FileResult?

后端 未结 9 1711
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 05:05

I\'ve had it suggested to me that I should use FileResult to allow users to download files from my Asp.Net MVC application. But the only examples of this I can find always h

9条回答
  •  旧时难觅i
    2020-11-22 05:21

    The MVC framework supports this natively. The System.Web.MVC.Controller.File controller provides methods to return a file by name/stream/array.

    For example using a virtual path to the file you could do the following.

    return File(virtualFilePath, System.Net.Mime.MediaTypeNames.Application.Octet,  Path.GetFileName(virtualFilePath));
    

提交回复
热议问题