tags:

views:

45

answers:

2

Hi friends,

Would it be possible to extract the mimetype by importing shell32.dll in C#? Can anyone help me on this?

For example: for pdf it should retrieve -Adobe Acrobat Document

I could be able to extract using regkeys, but I'm looking for a way to extract using shell32.dll

+1  A: 

C# calls into native DLLs using P/Invoke. If there is a function or set of functions exposed in shell32 that does what you want, there is almost certainly an example for it on pinvoke.net

Steve Gilham
A: 

It's not really the MIME type but you can use this :

http://pinvoke.net/default.aspx/shell32/SHGetFileInfo.html

With SHGFI_TYPENAME in the uFlags parameter, it should return what you meant in your question. It didn't try it, let us know.

speps
Thanks Speps , I could able to get the typeName ..Thanks a ton :)
Andy
in hope of nyone finds this useful..uint flags = SHGFI_SYSICONINDEX | size | SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME ; SHGetFileInfo(path, 0, out info, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), flags);string typeName = info.szTypeName;
Andy