Open a file with other extension using C# [closed]
I have file with .xml extension.开发者_Go百科 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?
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();
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.
Visual Studio's default editor for other file extensions is set in Tools | Options | Text Editor | File Extensions.
精彩评论