Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取打开c#应用程序的文件位置_C#_Visual Studio - Fatal编程技术网

获取打开c#应用程序的文件位置

获取打开c#应用程序的文件位置,c#,visual-studio,C#,Visual Studio,我正在尝试制作一个基本的控制台应用程序(比如commandpropmt) 我试图做的是(简单地说)如果我右键单击一个文件,让我们将其命名为my.file,然后单击open with并选择我的控制台应用程序来运行该文件。如何获取我的.file位置 我什么都试过了,在网上搜索,什么也没找到。 谢谢很简单,打开的文件作为参数发送到程序。因此,查询args以获取文件名 static void Main(string[] args) { //Returns the path to the file

我正在尝试制作一个基本的控制台应用程序(比如commandpropmt)

我试图做的是(简单地说)如果我右键单击一个文件,让我们将其命名为my.file,然后单击open with并选择我的控制台应用程序来运行该文件。如何获取我的.file位置

我什么都试过了,在网上搜索,什么也没找到。
谢谢

很简单,打开的文件作为参数发送到程序。因此,查询args以获取文件名

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()); 

}



打开的文件作为参数发送到程序,这很简单。因此,查询args以获取文件名

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()); 

}