I have file with .xml extension. Using C# i have to open the file with another extension, like .exe for example. I can open the file with the 'Open With' option manually. Now I have to do the same using C#. How do I do that?
Asked
Active
Viewed 1,227 times
3 Answers
5
I'm guessing your question is that you want to open a File using C# with any program you specify.
You'll have to launch the file as an argument of a process that can support the file type:
Process process = new Process();
process.StartInfo.FileName = "SomeApplication.exe"; // The app to "Open With..."
process.StartInfo.Arguments = "'C:\\YourFile.xml'"; // The file to open
process.Start();

djdd87
- 67,346
- 27
- 156
- 195
-
2
-
2@jonathon - Mind reading is a necessary skill for a programmer. How else are we meant to know what clients want? – djdd87 Jul 06 '10 at 09:09
1
string xmlname = "c:\\test.xml";
string exename = System.IO.Path.ChangeExtension(xmlname, "exe");
I reread your question. I think you want to start the application with the Process.Start()
method.

codymanix
- 28,510
- 21
- 92
- 151
0
Visual Studio's default editor for other file extensions is set in Tools | Options | Text Editor | File Extensions.

Richard
- 106,783
- 21
- 203
- 265