Clack Clack - 2 years ago 95
C# Question

How to get correct file extension when you know content-type

I have a byte[] containing data for a file. Array can contain data for several different filetypes like xml, jpg, html, csv, etc.

I need to save that file in disk.

I'm looking for a c# code to find out proper file extension when you know content-type, but aren't sure for the file extension?

Answer Source has a snippet for doing this, essentially looking up the extension in the registry under HKEY_CLASSES_ROOT\MIME\Database\Content Type\<mime type>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download