Question File Type Associtions

Vermiculus

Well-known member
Joined
Jul 28, 2008
Messages
55
Location
Baltimore
Programming Experience
1-3
Hello! I am trying to create a new file type to go with my program, and create the file associations for it. I thought you could do this from the Project Properties -> My Extensions tab, but it seems I was mistaken.. I'm not exactly sure.

But what I want to do is 'protect' a text document by saving it under a different file extension, and then reloading the information back again onto the form when it is recalled. I really have no idea where to start. :(
 
File associations are stored in the Registry for each system. If you're using a paid-for version of Visual Studio then you can create a Setup project to build an MSI installer for your application and use that to create the file association. If you want to use ClickOnce deployment simply copy the files across to the destination then you're either going to have to have the user create a association manually in Windows or else edit the Registry yourself in code.

Once the file association exists then double-clicking a file with that extension will open your application and pass the file path as a commandline argument. It's up to you to use that file path in whatever way is appropriate, e.g. open the file and display its contents. You can do that using e.CommandLine property in the application's Startup event handler or else the Environment.GetCommandLineArgs method anywhere.

You may already be aware but just note that creating the file association simply creates a default action for files with that extension. It doesn't prevent the user opening that file in another application though. Visual Studio is a prime example. The SLN and VBPROJ files that store solution and project information are just text files. If you double-click one they will open in VS, but that doesn't mean you can't still open them in Notepad and view the contents. If you genuinely want to protect the contents of a file then you'll need to encrypt it.
 
the whole Setup project thing is still pretty knew to me..
Then I suggest that you read and experiment. There's no point my telling you everything here when you could work out or read most of it for yourself. There is plenty of information in the MSDN Library about creating Setup projects. You can create one for yourself and then use the F1 key and Dynamic Help to go straight to the topics you need. You can then ask specific questions about the parts you can't work out. With regards to this topic, you should pay special attention to the File Types Editor in your Setup project.
 
Add an Action to an Existing Extension

Is there a way using the Installer to add an action to an existing extension without causing any changes to the existing actions for that extension?

For example if I have a .txt file and double click on it it opens in Notepad. What if I want to do is to add my program to the right click list so if you double click on the txt file it still opens in Notepad but if you right click on any text file you see My Application in the list of apps.

Manually you would:
1. Open Windows Explorer
2. Select Tools, Folder Options
3. Select the File Types Tab
4. Find the extension in the list
5. Click the Advanced button
6. Click the New button
7. Add the the new action

How can this be done with the installer or programmatically? Thanks in advance for any information or direction.

- Barkley
 
Barkley,

Look in MSDN about reading and writing registry values. Then you can do a google search to find the specific registry key that handles the "right click > open with" list.

You can write up code to first check the registry and determine if your program is listed in the "open with" key, and if not then to add your program to the list.

I would give you the code but I'm working on something else and its a good learning experience for you to do it yourself. You can post back with your code if you want for critiquing.

-Micah
 
Back
Top