Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am tring to make some file extention associated to my application like make any file with .ztr work directly with my app when user double click that file I am using VS2012 , C# , Windows 7 I did simulate this Example here
https://www.youtube.com/watch?v=s_YUcBxc5xM[^]

sure with some modification like fix Import Dll put also faild.

C#
public static void Register   (string Ext,string Program,string Ico)
{
    string prog = Path.GetFileName(Program);
    RegistryKey file = Registry.CurrentUser.CreateSubKey("Software\\Classes\\"+Ext);//.osa
    RegistryKey App = Registry.CurrentUser.CreateSubKey("Software\\Classes\\Applications\\" + prog);//osama.exe
    RegistryKey Link = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Ext);//.osa

    file.CreateSubKey("DefultIcon").SetValue("", Ico);
    file.CreateSubKey("PerceivedType").SetValue("","Text");

    App.CreateSubKey("shell\\open\\command").SetValue("", "\"" + Application.ExecutablePath + "\"%1");
    App.CreateSubKey("shell\\edit\\command").SetValue("", "\"" + Application.ExecutablePath + "\"%1");
    App.CreateSubKey("DefultIcon").SetValue("", Ico);

    //There is Change here you 
    Link.CreateSubKey("UserChoice").SetValue("Progid", Program);
    Invoke.SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
}
Posted
Updated 25-Feb-14 21:20pm
v2
Comments
Kornfeld Eliyahu Peter 26-Feb-14 3:28am    
Read here - http://www.codeproject.com/Articles/43675/C-FileAssociation-Class

I don't really know what happens, partially because you did not define 'failed'.

I would start by modifying these two lines:
C#
App.CreateSubKey("shell\\open\\command").SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\"");
App.CreateSubKey("shell\\edit\\command").SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\"");


This way, both the executable path and the command-line arguments will be enclosed between their own quotes.
 
Share this answer
 
Comments
osamaworx 26-Feb-14 3:47am    
Unfortunately Not working also
but can you explain to me without code what happen when assign file extention to App
what paths in registry have Update and values for update ?
Have a look here:
C#: Set File Type Association[^] - it is very interesting article ;)
and also StackOverflow KB: Associate File Extension with Application[^] - they suggest to use ClickOnce[^] and to not torture yourself writing custom functions ;)
 
Share this answer
 
v2
Comments
osamaworx 26-Feb-14 5:54am    
I appreciate your help Unfortunately Not working also
Maciej Los 26-Feb-14 9:31am    
:laugh:
"Not working" is not informative at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900