Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted
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.
Posted

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?

  • Leaders
Posted

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.

Posted

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.

:)

  • *Experts*
Posted

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()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...