获取打开c#应用程序的文件位置
我正在尝试制作一个基本的控制台应用程序(比如commandpropmt) 我试图做的是(简单地说)如果我右键单击一个文件,让我们将其命名为my.file,然后单击open with并选择我的控制台应用程序来运行该文件。如何获取我的.file位置 我什么都试过了,在网上搜索,什么也没找到。获取打开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
谢谢很简单,打开的文件作为参数发送到程序。因此,查询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());
}