-1

I know that if i write System.Diagnostics.Process.Start( "notepad.exe", "text.txt"); a certain file will open in notepad. I want to make all files with a certain extension like .xml open in notepad. I have a program made in C#, the program can browse through files and if i hit double click they will open with the program windows sets on default. Now i don't want to change that default program, i just want to write some code to open all .xml programs with notepad (only while the program is on)

Paul Moldovan
  • 464
  • 2
  • 5
  • 17
  • You mean, while the program is running, if I double click an xml file in explorer, it should open in notepad? Or only files opened from your application should open in notepad? – SWeko Aug 03 '11 at 10:23
  • I am not sure notepad can support more than one file opened. do you want to open all xml file in multiple notepad sessions? or you want to change the .xml default "open program" windows association? – NirMH Aug 03 '11 at 10:29
  • 3
    Sounds like a horrible user experience. – Uwe Keim Aug 03 '11 at 10:37
  • 1
    This would depend on the user's system settings. You would need to change the default program from the .xml file extension. Of course ANY program that does this without my permission ( besides its own file extension ) will NEVER be used by me. – Security Hound Aug 03 '11 at 11:40

3 Answers3

3

There is no such a direct way to do it, a work ground is Whenever you start your application, update the registry "I think something under HKEY_CLASSES_ROOT" to open that file extension "xml" with the program you want "notepad". before your program exit reassign that default program. However if your program doesn't successfully terminated, the default will be as you set it before.

Jalal Said
  • 15,906
  • 7
  • 45
  • 68
2

You can achieve this by following these steps, but for these steps to work you should have access to registry

  1. First get the default application for the xml files in the current machine and store it in a global variable on your application start(i.e. generally that is when the main form of your application loads)
  2. Then change the default application of the xml files in the registry to notepad or any other application of your choice
  3. Now you have set the notepad as the default application for opening XML files
  4. While Exiting the application make sure you reset the default application that you have stored in the global variable from the first step to the registry
Community
  • 1
  • 1
Vamsi
  • 4,237
  • 7
  • 49
  • 74
0

Yeah I kinda solve it. So i took the path from when I opened the file, the name of the file but just the last 4 characters and if the last 4 characters were ".xml" then i wrote System.Diacnostics.Process.Start("notepad.exe",pathtofile);

It worked.

Paul Moldovan
  • 464
  • 2
  • 5
  • 17