-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# icon-associator | ||
## Description | ||
Makes creating and removing file associations easier.<br> | ||
Also calls `SHChangeNotify()` to automatically update your file associations, and can even help sometimes if you have associated another program with a different file type, and the association for that isn't updating. | ||
|
||
## How To Use | ||
This code is made assuming you have already referenced `icon-associator.dll` in your project, and is using `System.Windows.Forms.dll` for the example.<br> | ||
Also, the two examples for adding and removing file associations should not be added in the same code block, they should be separate, as the removal would negate the addition, making usage of this library useless. | ||
```csharp | ||
str_ExampleExtension = ".example"; | ||
|
||
FileAssociation association = FileAssociation.CreateOpenInfo( | ||
Application.ExecutablePath, str_ExampleExtension, | ||
// returns "<EXECUTABLE_PATH>" "%1" with <EXECUTABLE_PATH> being the file path to your .exe | ||
FileAssociation.DefaultCLI(Application.ExecutablePath) | ||
); | ||
|
||
// add the association to your device registry if not already there | ||
if (!AssociationManager.CheckForAssociationInfo(association)) | ||
AssociationManager.AddAssociationInfo(association); | ||
|
||
// remove the association from your device registry if there | ||
if (AssociationManager.CheckForAssociationInfo(association)) | ||
AssociationManager.RemoveAssociationInfo(association); | ||
``` |