简体   繁体   中英

Get file location that opened c# application

i am trying to make a basic console application (like command propmt)

what im trying to do is (in simple terms) is if i right click a file, lets call it my.file and i click open with and select my console application to run that file. how can i get my.file location.

I have tried everything and searched on the internet and found nothing. Thanks

Its simple the file being opened is sent as arguments to the program. So query the args to get the filename

static void Main(string[] args)
{
    //Returns the path to the file
    Console.WriteLine(args[0]); 
    // Index 1 returns file path, while index 0 returns the executable path
    Console.WriteLine(Environment.GetCommandLineArgs()[1].ToString()); 

}


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM