Determine file type

  • Thread starter Thread starter Leo Pedeglorio
  • Start date Start date
L

Leo Pedeglorio

Hi Everyone!

Does anybody know how to determine the type of a file? I already tried
FileInfo and it has the Extension property but what I want is the
description. For example,
".xls" the description is Microsoft Excel Worksheet.

Thanks,
 
Hi Everyone!

Does anybody know how to determine the type of a file? I already
tried FileInfo and it has the Extension property but what I want is
the description. For example,
".xls" the description is Microsoft Excel Worksheet.

Thanks,

You'll need to use an API call:

public static string JGetFileType(string strFilename)
{
SHFILEINFO psfi = new SHFILEINFO();
string strFileType = "";
uint uFlags = (uint)(JConst.SHGFI_ICON | JConst.SHGFI_SMALLICON |
JConst.SHGFI_TYPENAME | JConst.SHGFI_ADDOVERLAYS |
JConst.SHGFI_SYSICONINDEX);

IntPtr ipIcon = JGDLL.SHGetFileInfo(strFilename, 0, out psfi,
Marshal.SizeOf(psfi), uFlags);

// Check result
if (ipIcon != IntPtr.Zero)
{
strFileType = psfi.szTypeName;
}
else
{
strFileType = "";
}
return strFileType;
}

You probably don't need all of those flags, I copied this from another
function that gets icon details as well, key one is SHGFI_TYPENAME.
 
Back
Top