Take the file extension and see it in the registry. The record for it will have the "Content Type" property.
Here is a complete example of returning a FilePathResult from a controller action:
string filePysicalPath, fileName; //these need to be set to your values. var reg = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey( Path.GetExtension( filename ).ToLower() ); string contentType = "application/unknown"; if ( reg != null ) { string registryContentType = reg.GetValue( "Content Type" ) as string; if ( !String.IsNullOrWhiteSpace( registryContentType ) ) { contentType = registryContentType; } } return File( filePysicalPath, contentType, filename );
source share