2011-05-31 1 views
1

Comment puis-je ajouter une application de manière prgramatique au menu Ouvrir avec pour un type de fichier donné?C# Association de types de fichiers

E.g. J'ai fait un simple visualisateur de fichiers texte, j'ai fait le projet d'installation pour le même, Je veux associer l'afficheur de fichiers texte avec tous les fichiers .txt dans le système, Quand un utilisateur double-clique sur n'importe quel fichier .txt alors mon application devrait ouvrir.

Open with menu http://i4.photoblog.com/photos/27294-1306838510-0.jpg

Répondre

1

Vous devez changer l'entrée du Registre: HKEY_CLASSES_ROOT\txtfile\shell\open\command. Jetez un oeil avec regedit.exe. Vous pouvez également jeter un oeil à cette clé: HKEY_CLASSES_ROOT\.txt

Pour manipuler une entrée de registre, utilisez System.Win32.Registry ici Docs.

1

est ici une façon (en VB). ApplicationTag est un nom court pour le Registre, tel que editor3.1. Vous pouvez vérifier le registre avec regedit pour voir ce qui se passe, et vous pouvez vouloir faire un point de restauration avant de tester cette partie de votre application.

Imports Microsoft.Win32 

...

Registry.SetValue("HKEY_CURRENT_USER\software\classes\" & FileType, "", applicationTag) 
q = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & FileType, True) 
If q IsNot Nothing AndAlso q.GetValue("ProgID", "notfound") <> "notfound" Then 
    q.SetValue("ProgID", appTag) ' for the local user, overrides hkcr 
    End If 
appKey = "HKEY_CURRENT_USER\software\classes\" & applicationTag 
Registry.SetValue(appKey, "", "text") 
Registry.SetValue(appKey & "\shell", "", "open") 
Registry.SetValue(appKey & "\shell\open", "", "") 

Registry.SetValue(appKey & "\shell\open\command", "", """" & ApplicationPath & """ ""%1""") 
Registry.SetValue(appKey, "", "text") 
appKey = "HKEY_CURRENT_USER\software\classes\CLSID\" & ApplicationGuid 
Registry.SetValue(appKey, "", applicationTitle) 
Registry.SetValue(appKey & "\ProgID", "", applicationTag) 
Questions connexes