Get file type/format without the file extension

mach_9

Member
Joined
May 24, 2016
Messages
20
Programming Experience
5-10
I am looking to get the file type of a file without its extension. I have found some links noted below, but I when I use the code, it seems to always return ?application/octet-stream?. I have tested Word 2007 documents and other file formats with no success.

Just a bit of background, we store supporting documents in the DB and I would like to know what file format they are. We do have the extension saved but sometimes it is the incorrect extension for that file.

Some links that I have found:
http://stackoverflow.com/questions/1437382/get-file-type-in-net

I?ve tried all of the examples from the link below but with no luck.
http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature

Maybe I am doing something wrong, any help would be much appreciated.

Using VS 2010, Windows 7, Oracle 11 DB.

Thanks
 
Typically you'd just use the file extension to know what type of file it is, however without using the file extension there's ways to find out what type of file it is by checking what encoding the file has (whether it's ascii, unicode, binary; and of the text types is it xml, delimited, plain text, etc) but from your post you're talking more about the file's mime type, which is where you're seeing values like "application/octet-stream" and here's a link on getting file mime types: c# - Get MIME type from filename extension - Stack Overflow
 
Back
Top Bottom