4

In my application I create files with extension .mprj.

How can I assign an icon to this type of file?

Does appropriate .Net methods exist?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Diana
  • 229
  • 1
  • 5
  • 14
  • Would associating the file type to your program be an acceptable solution? – George Duckett Nov 17 '11 at 10:48
  • Related thread - http://stackoverflow.com/questions/69761/how-to-associate-a-file-extension-to-the-current-executable-in-c-sharp – KV Prajapati Nov 17 '11 at 10:49
  • This has been thoroughly answered in the following thread: http://stackoverflow.com/questions/2993118/how-to-perform-shell-icon-embedding-in-visual-studio-2010/10415947#10415947 – Blake Niemyjski May 02 '12 at 14:39
  • This has been thoroughly answered in the following [stack overflow thread](http://stackoverflow.com/questions/2993118/how-to-perform-shell-icon-embedding-in-visual-studio-2010/10415947#10415947). We've been using this implementation and it works great. It is also open source and integrates into MSBuild. – Blake Niemyjski May 02 '12 at 14:39

2 Answers2

3

you need to modify registry entries. A code snippet how to do with c# can be found here: http://mel-green.com/2009/04/c-set-file-type-association/

Steve
  • 1,072
  • 11
  • 28
  • 2
    Remember that specified icon won't be visible for that extension until you close or kill any `Explorer.exe` process and then restart it! Rebooting Windows is another solution. – Marco Nov 17 '11 at 10:54
1

I advise you to use InnoSetup to do that. You can assocaite a program with an extension to add icons, and to launch program when an users click on a file with this extension. (for example to open the file directly in the program like msoffice programs). When we click on an Excel file, Excel is launching and open this file. You can do the samething easy with InnoSetup and little code in main method to parse arguments.

With Innosetup you just add iIn the section [Setup]

ChangesAssociations=yes

And in the section [Registry]

Root: HKCR; Subkey: ".mpl"; ValueType: string; ValueName: ""; ValueData: "{#MyAppName}"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}"; ValueType: string; ValueName: ""; ValueData: "Program {#MyAppName}"; Flags: uninsdeletekey
Root: HKCR; Subkey: "{#AppName}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKCR; Subkey: "{#AppName}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}.EXE"" ""%1"""

More information in this previous message

Community
  • 1
  • 1
v20100v
  • 696
  • 4
  • 11