c# How to get the file path from 'Open With

2019-08-03 11:22发布

问题:

I'm making a text editor and I'm trying to make a code to get the file path of a file when it's open in a application using 'Open With'.

Details: 'Open With' is an option when you right click on a file. The file then becomes a shortcut to the application. I have tried to use Process , but I couldn't seem to get the path from a file process.

Question: In c#, how do you get the file path of a file when using 'Open With'?

EDIT: Application path is C:\Users\Mayhem\Documents

Text file path is C:\Users\Mayhem\Desktop

I need to get the file path of 'text file'.

回答1:

My goal is to get the path of a file using 'Open With'. This code shows all paths opened with the application, including the file path.

string[] openedPaths = Environment.GetCommandLineArgs();