2

Possible Duplicate:
How to associate a file extension to the current executable in C#

I dont know how exactly to call this issue.

I am looking for a solution such as: my .net application will be automatically opened when a filetyle defined for that application is open.

For example: the filetype of that application has an extension xyz: hellothere.xyz

Whenever, the user opens the file with an extension "xyz" then that .net application will be opened. How can I achieve this?

Thanks in advance.

Community
  • 1
  • 1
olidev
  • 20,058
  • 51
  • 133
  • 197

6 Answers6

2

A file association can be created manually in Windows Folder Options. This article describes how to do it programmatically, for example with a registry file:

  • Create a string key for your file extension in HKEY_CLASSES_ROOT named .xyz.

  • Set its value to the name of your file type, e.g., XyzDocument.

  • Create a string key HKEY_CLASSES_ROOT\XyzDocument\open\shell\command.

  • Set its value to "path\to\your\program" "%1" or similar, per your needs.

You can also do it from a batch script with ftype and assoc:

ftype XyzDocument="path\to\your\program" "%1"
assoc .xyz=XyzDocument
Jon Purdy
  • 53,300
  • 8
  • 96
  • 166
1

The term you are looking for is "file association". The best place to create a file association for your application is in your installer. The exact process depends on what installer technology you are using.

Christian Hayter
  • 30,581
  • 6
  • 72
  • 99
0

This is not a coding issue but an OS configuration issue.

For windows, you need to setup a file extension association with your program.

See this How to from Microsoft.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

Something like this: How to change or select which program starts when you double-click a file in Windows XP

?

Aerik
  • 2,307
  • 1
  • 27
  • 39
  • I would like to do it automatically without opening and selecting which application to run. – olidev Dec 06 '11 at 18:57
0

If I am not mistaken, you want to register a filetype with your application. You can do this by right-clicking a file of that type, selecting Open with, and select your application.

EDIT Per your comment, devn, I see that you want to do this at install time. That being the case, you could use WiX to accomplish this like here.

Community
  • 1
  • 1
Mark Avenius
  • 13,679
  • 6
  • 42
  • 50
  • but I want to do it automatically. let's assume that a mp3 file, when I click on it, winamp will be opened. I dont know whether I can do this during the .NET setup process? – olidev Dec 06 '11 at 18:56
0

You need to create a file association during the installation. For a walkthrough of creating that, see the "Creating a File Association" section of this MSDN article on creating that association during install.

Note: others have posted articles on how to do this manually, but I think you're mention of uses means you want to do this during setup.

Tim Hoolihan
  • 12,316
  • 3
  • 41
  • 54