开发者

Make all .xml files open in notepad in C sharp [closed]

开发者 https://www.devze.com 2023-03-25 02:55 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Closed 9 years ago.

开发者_高级运维 Improve this question

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)


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消