dotnetgirl Posted October 17, 2003 Posted October 17, 2003 Hello All, Can anybody tell me how the word document for example opens in MS-word on double clicking the document in explorer. How this file type association is done with corresponding editor. i want to do it in Vb.Net or C#. Any clues? Thanks. Quote
*Experts* Volte Posted October 17, 2003 *Experts* Posted October 17, 2003 It uses the [api]ShellExecute[/api] API function, but .NET can do it with Process.Start. The file associations are stored in the registry under HKEY_CLASSES_ROOT I think. Quote
dotnetgirl Posted October 17, 2003 Author Posted October 17, 2003 Yeah, i know that Process.start can help us to start a perticular process in an event. I can say that my question is more related with file type association with that application. How will i come to know that on clicking a file, i have to open this application and run the openDocument function from it, for example. Inside the openDocument function, i can handle the process and start an instance of the child window. But before that how can i associate the document and application? Can u focus more on this? Quote
Leaders Squirm Posted October 17, 2003 Leaders Posted October 17, 2003 Its all down to the registry. Let's imagine you wish to register a file type called MyApp Document with the .xyz extension. First create the following key: HKEY_CLASSES_ROOT\MyApp.Document\Shell\Open\Command In this key you place the command-line statement you wish to be executed when a file of type MyApp.Document is opened. The variable %1 denotes the filename. Some example values might be: C:\Program Files\MyDir\MyApp.exe %1 C:\Program Files\MyDir\MyApp.exe "%1" C:\Program Files\MyDir\MyApp.exe OPEN "%1" Next, you need to associate the extension .xyz with MyApp.Document. You do this by creating the following key: HKEY_CLASSES_ROOT\.xyz In this key set the value to MyApp.Document. This completes the file association process. To associate an icon with your file, create the following key: HKEY_CLASSES_ROOT\MyApp.Document\DefaultIcon In this key place the full path and name of the module (EXE or DLL) which contains the icon followed by a comma and then the resource index of the icon you wish to use within the module. Quote Search the forums | Still IRCing | Be nice
dotnetgirl Posted October 17, 2003 Author Posted October 17, 2003 Thanks Squirm! now i ve clear idea. I shall try it out. Now my next question is, once a file type is asssociated with a perticular application, how to pass that document as a parameter so that the application is run to execute open function to open that perticular document. Means .Net, how to go about it? Thanks. :) Quote
*Experts* mutant Posted October 17, 2003 *Experts* Posted October 17, 2003 The name of the file is automatically passed to your program. You can retrieve command line arguments like this: 'to get the command line separated System.Environment.GetCommandLineArgs() 'to get the whole command line as one string System.Environment.CommandLine() Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.