Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MimeMapping in ASP.NET Core

I'm trying to move my old mvc5 project to asp net core. Old code was:

public string ContentType {     get     {         if (!string.IsNullOrEmpty(FileName))             return MimeMapping.GetMimeMapping(FileName);         return null;     } } 

Error is

The name 'MimeMapping' does not exist in the current context

enter image description here

like image 651
Sauron Avatar asked Dec 07 '15 10:12

Sauron


1 Answers

The following code should work:

string contentType; new FileExtensionContentTypeProvider().TryGetContentType(FileName, out contentType); return contentType ?? "application/octet-stream"; 
like image 124
Mark G Avatar answered Sep 18 '22 08:09

Mark G