Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a C# Application work as the default program for certain files? [duplicate]

Tags:

c#

My application has a picture box in it. When I open an image in Windows, instead of the default program that opens to show that image, I want to use my own application and have that program containing the picture box show the image.

like image 974
Pedrum Avatar asked Oct 17 '11 04:10

Pedrum


People also ask

How do they make AC?

An air conditioner is made up of a condenser, an inside compressor, an outside compressor, copper pipes, a fan, and controls. Once these are all available, the unit is assembled. First the condenser and inside compressor, then the copper wires that connect them to the fan and outside compressor.

How can you make an air conditioner without electricity?

The technique is simple – cut plastic bottles in half (make sure the plastic bottles do not have a wide mouth) and then mount them on a board in a grid like pattern. Voila! AC ready!


1 Answers

I did this recently, though I used a different action, not the default Open action.

First you find out file type of some extension, say .jpg:

var imgKey = Registry.ClassesRoot.OpenSubKey(".jpg")
var imgType = key.GetValue("");

Then you find out the path to your executable and build the "command string":

String myExecutable = Assembly.GetEntryAssembly().Location;
String command = "\"" + myExecutable + "\"" + " \"%1\"";

And register your executable to open files of that type:

String keyName = imgType + @"\shell\Open\command";
using (var key = Registry.ClassesRoot.CreateSubKey(keyName)) {
    key.SetValue("", command);
}
like image 199
Miserable Variable Avatar answered Oct 06 '22 11:10

Miserable Variable