how-to find the file type of a file?

  • Thread starter Thread starter Pierre Drapeau
  • Start date Start date
P

Pierre Drapeau

I am looking at a way to get the file type of a given file. The Windows API
has GetFileVersionInfo which will retreive that info, burried into a
structure. I tried to find the equivalent in C# and found
System.Diagnostics.FileVersionInfo. I see that the class has pretty much all
the information but the file type. Is there another class that will give me
the file type of a given file? I would prefer not using PInvoke and
GetFileVersionInfo, especially since I would have to write unsafe code.

Thanks, Pierre
 
Pierre,

Making a call through the P/Invoke layer is not unsafe. Unsafe code is
different from unmanaged code.

This information is not exposed, as you have found. You will have to go
through the P/Invoke layer to do this. You might be able to go through the
System.Management namespace as well, but I think that is a bit of overkill.

Hope this helps.
 
Back
Top