Register file type and custom document icon in .NET.

I have an application that creates files. I would like to associate these files with the application so that double-clicking on the file launches my application.

Everything works correctly, except for the annoyance that the icon looks the same as the icon of my application. I would like to have one icon for the application and one icon for it.

The DefaultIcon value in the registry requires the syntax "app.exe, 1", where 1 is the icon index. It seems that .NET resources are not Win32 resources.

I tried to follow, but to no avail:

  • Select "Embedded Resource" as a file.
  • Adding an icon to a resource file.

The only thing that worked was the icon file, separated from the executable file and pointing to it. However, it seems to me that this is surrender.

Any ideas how to solve this?

+4
source share
4 answers

Have you tried setting 2 as an icon index?

EDIT: I found a way, but you have to do it again for every new build.

  • Open the .exe file in Visual Studio (File โ†’ Open File)
  • Right-click the icon folder and select "Add Resource"
  • Click Import
  • Select .ico file
  • You may have to mess up the icon numbers, I think the lowest number (example 101) will be the application icon
  • Remember the new icon number and set it as an index

EDIT 2: Try this article: http://www.codeproject.com/KB/dotnet/embedmultipleiconsdotnet.aspx

+4
source

If you use the Wix toolkit ( http://www.wixtoolset.org ) to install the application, you can get Wix to take care of the file type and register the document icon

Here is my Vince magic spell:

<!-- Your executable --> <File Id="MaAppExe" Name="MyApp.exe" Source="MyApp.exe" KeyPath="yes" > </File> <!-- your document icon --> <File Id='IconMyAppDoc.ico' Name='IconMyAppDoc.ico' Source='$(var.MyApp.ProjectDir)\Resources\Images\Icons\docicon.ico' /> <-- File Extension and associated document icon --> <ProgId Id='MyApp.MyAppExtension' Description='My App Data File' Icon='IconMyAppDoc.ico'> <Extension Id='MyApp' ContentType='text/plain'> <Verb Id='open' Command='Open' TargetFile="MyAppExe" Argument='"%1"' /> </Extension> </ProgId> </Component> 
+1
source

DefaultIcon will also take the path to the actual .ico file as an icon.

0
source

You need to make sure that your project has Win32 badges, not just .net badges. I HOPE someone points out an easy way to do this, but at the same time goes here ...

Compile your assembly, then from Visual Studio select "File โ†’ Open โ†’ Open File", open the assembly assembly. Add the icon that you want to use for documents, and set its identifier over the one used for your application. Save the assembly. You now have available Win32 resources.

- Change -
After editing his post, ZippyV seems to have a very good answer.

0
source

All Articles