views:

44

answers:

2

I've written a log parser, with some generous and insightful help from the SO community:

http://stackoverflow.com/questions/2906630/keeping-the-ui-responsive-while-parsing-a-very-large-logfile

Now, I'd like to be able to right click one of these logs, select "MyNewLogParser" from "Open With.." and see it open in my new program.

This would require me to

  • Change something about my XP installation to show my program in the dropdown list
  • Change the program so that it knows to open the selected file and run the parsing.

What do you call these things, and how is it done? I don't know what to search for...

A: 

To open the selected file, you need to implement command-line parameters. Take a look at your Program.cs file and the Main function.

You want its signature to look something like this:

static void Main(string[] args)
{
}

The args array will be the array of command-line params passed to your application. So if you ran MyNewLogParser myLog.txt, the contents of args[0] would be myLog.txt.


For the OpenWith... menu, you'll need to modify the registry. Search for the "OpenWith" key in Regedit and you'll find it. On my machine (Windows 7), it's in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts. I'm not sure on the exact details of how it works, but Google should be able to help you out from there.

If you don't want to do it programmatically, I'm pretty sure there's some menu item that allows you to select the application that will open a file. Don't recall what it is on XP, though. Alternatively, you can associate a file extension with your application through a tab in the Folder Options dialog, so that double-clicking it opens your application.

Anna Lear
And how would I get my program in the selection box?
Carlos
Which selection box? The one for Open With... is just a file browser, if I recall, so you can navigate to wherever your program is installed and pick the executable.
Anna Lear
Does it populate the list when I use it first time? I don't want to have to select the exe file every time I use it...
Carlos
Booted up an XP VM and it looks like your options are "edit the registry" or "use the 'Browse' button in the Open With dialog to navigate to your parser". The latter is probably the easier and safer of the two.
Anna Lear
There's a checkbox in the Open With dialog to "Always use the selected program with this kind of file". That will associate your parser with the file extension of your log file. Even if you don't select it, your parser should be added to the Open With menu item after you select it once, yes.
Anna Lear
Wow, sweet. It seems the first argument passed is simply the path of the file I selected. Also selecting my program from the list puts it in the shortlist for next time. Problem solved
Carlos
A: 

Assuming that your file logs have specific file extension, you need to add OpenWithList keys in the registry. See this MSDN page for more information:

http://msdn.microsoft.com/en-us/library/bb166549%28VS.80%29.aspx

ho1