By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,320 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,320 IT Pros & Developers. It's quick & easy.

getting file icon

P: n/a
hi, how can i get the icon associated with a certain file type? thanks
--
-iwdu15
Sep 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I had this document, it should help you.

How many times have you created your own application and wondered,
"Gee, this thing creates data files--how can I associate my data file
with my application, so that when a user double-click on the data file,
my application starts up and runs it?"

Well, you probably didn't think quite like that, but if you use Word,
you know that if you double-click on a "*.doc" file, Word opens up and
*poof* there's your document.

Introduction
So how do you do that with VB.NET?

There are two ways, the easy way and the hard way. The easy way is best
because if your application gets uninstalled, so will your file
associations. But, you might have occasion to need the hard way. I'll
cover the hard way in a later faq.

Walk Through
The easy way

1. Open up your solution in Visual Studio. If you don't have Visual
Studio, I guess you're out of luck and have to use the hard way.

If you haven't already, add a Setup Project to your solution by File,
Add Project, New Project, Setup & Deployment Projects, Setup Project.

2. Right-click on your setup project in the "Solution Explorer" window,
select "View", then select "File Types".

You'll see the "File Types" window displayed in Visual Studio. At the
top of the window will be "File Types on Target Machine".

3. Right-click on "File Types on Target Machine". The menu will pop up
with "Add File Type" Click on this.

You will see "New Document Type #1" added, with "&Open" underneath it.

4. The "New Document Type #1" can be anything you want--change it to
something descriptive. Although the user never sees this, never use
something common--be as unique as possible, because you can overlay
current file associations without even realizing it. For example, you
might think "pngfile" might be a useful name--but using that will now
send all "*.png" files to your application, instead of to an image
viewer. A good practice may be to use "YourCompanyName.FileType", where
"YourCompanyName" is your name or your company's name, and "FileType"
is a descriptive text of your file.

5. In the "Properties" window for your new type, you will need to
change a few properties:

command: Change to the application you want to run. If you click
on the "...", you will be given your choices, and you will probably
want to locate and use the "Primary Output ..." file.
Description: This is what will show up when your file type is
seen in Windows Explorer.
Extensions: This is your list of extensions to associate with
this file type. You can list any number of extensions, just separate
with a comma, and you don't need to use a period. Avoid, at all costs,
using a common extension (such as ".doc"), because you will overwrite
any pre-existing types!
Icon: This will associate an icon with your file type, that
shows up in Windows Explorer.

6. Are we there yet? Almost--now we move on to that "&Open". This is an
action that is available if your right-click on the file. The default
action ("&Open" is currently set as the default) is what happens when
you double-click on the file. Right-click on your "New Document Type
#1" to add actions, but for the moment, lets define our "&Open" action.
Click on "&Open". You will see in the Properties window "Name",
"Arguments", "Verb". Verb is hidden from the user, but is the key that
is stored in the registry. Leave it the same as the name, but without
the "&". The default for "Arguments" is "%1", which means to pass the
full path and filename to your application. You can add other stuff
here as well, if you need to pass flags to your application to do
special stuff. All this information is getting passed to your
application on the command line, so you'll need to be familiar with the
"Environment.CommandLine" object.
If you need to set a different action as your default, just
right-click on the action and select "Set as Default"

Conclusion
And that's it. Now, when you build your setup project, the file
associations will be included, so that when a user installs your
application, the associations will be installed as well, and if
(hopefully never) the user uninstalls your application, then the
associations will be removed.

Sep 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.