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

后端 未结 9 1882
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 05:17

    If you're using .NET Framework 4.5 then you use use the MimeMapping.GetMimeMapping(string FileName) to get the MIME-Type for your file. This is how I've used it in my action.

    return File(Path.Combine(@"c:\path", fileFromDB.FileNameOnDisk), MimeMapping.GetMimeMapping(fileFromDB.FileName), fileFromDB.FileName);
    

提交回复
热议问题