Created
October 25, 2012 23:45
-
-
Save mahizsas/3956194 to your computer and use it in GitHub Desktop.
C# - GetMimeType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string GetMimeType(string fileName) | |
{ | |
string mimeType = "application/unknown"; | |
string ext = Path.GetExtension(fileName).ToLower(); | |
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext); | |
if (regKey != null && regKey.GetValue("Content Type") != null) | |
{ | |
mimeType = regKey.GetValue("Content Type").ToString(); | |
} | |
else if (ext == ".png") | |
{ | |
mimeType = "image/png"; | |
} | |
return mimeType; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment