473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

type of file from extension but no filename

Hello,

I want to get a list of file types from a big list of extensions.

I know there exists an api call (see below), but it only works when you have
a file name.
SHGetFileInfo(FileName, 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_TYPENAME)
Return shinfo.szTypeName

But this only works when passing an actuual filename (fe:
"C:\WINDOWS\WIN.INI")
When getting the icon from only the extension seems to work:
hImgLarge = SHGetFileInfo(ext, 0, shinfo, Marshal.SizeOf(shinfo),
SHGFI_USEFILEATTRIBUTES Or SHGFI_ICON Or SHGFI_LARGEICON)
Return System.Drawing.Icon.FromHandle(shinfo.hIcon)

Here I can pass the extension only (fe: ".exe")
Is this possible?
Grtz.
May 19 '06 #1
1 1100
>I want to get a list of file types from a big list of extensions.

I know there exists an api call (see below), but it only works when you have
a file name.
SHGetFileInfo(FileName, 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_TYPENAME)
Return shinfo.szTypeName

But this only works when passing an actuual filename (fe:
"C:\WINDOWS\WIN.INI")
When getting the icon from only the extension seems to work:
hImgLarge = SHGetFileInfo(ext, 0, shinfo, Marshal.SizeOf(shinfo),
SHGFI_USEFILEATTRIBUTES Or SHGFI_ICON Or SHGFI_LARGEICON)
Return System.Drawing.Icon.FromHandle(shinfo.hIcon)

Here I can pass the extension only (fe: ".exe")

The key is to specify SHGFI_USEFILEATTRIBUTES like you did for the
icon. Should work for the file type as well.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vilmar Brazão de Oliveira | last post by:
Hi, How verify type or extension of file using ASPUPLOAD? I check documentation, but I didn't find anything else yet. thanks, -- ««««««««»»»»»»»»»»»»»» Vlmar Brazão de Oliveira...
3
by: nbaxley | last post by:
I'm using a binary stream to send down a file with ASP from the web server. I've been having trouble with IE and getting it to recognize my file. I've added the filename as a...
0
by: Brian Henry | last post by:
I am using the following code to get the "Type" of a file Imports System.Runtime.InteropServices Public Class ShellAPI Public Declare Auto Function SHGetFileInfo Lib "shell32.dll" ( _ ...
6
by: Rob | last post by:
I want to copy files from one folder to another... but only if it is a ".txt" file... Below should work, but how would you filter on ".txt" files only ? Thanks ! Dim fileEntries As String()...
3
by: Phoe6 | last post by:
Hi all, I had a filesystem crash and when I retrieved the data back the files had random names without extension. I decided to write a script to determine the file extension and create a newfile...
5
by: Krustov | last post by:
I have the following list of image files . When searching the latest (numbered file) in this particular case its background_4.*** and its a .jpg file - but - the latest file in the list could...
3
by: plbaldri | last post by:
I have written a very simple and basic program for an intro Comp Sci class and am having trouble with it crashing. The program needs to accept a filename on the command line at the prompt and has to...
3
by: LordHog | last post by:
Hello, How would I go about finding the default handler, let's say a text file (*.txt), then launch the default handler with the file as an argument? I had found how to launch an external...
1
by: shahidrasul | last post by:
i want to download a file which user select from gridview, downloading is completing without problem but after download i want to refresh my page because i do some changes in db . but when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.