您可以将 Windows 设置为使用 Word 或其他应用程序打开 .doc 文件。我如何创建这样一个 c# 应用程序,它可以处理,例如,如果我用该应用程序打开一个 .txt 文件?所以计划是:有一个 information.kkk 文件,它是一个文本文件,里面有一个数字。我希望我的 C# 应用程序 (Visual Studio 2010) 在打开文件时收到该编号。
最佳答案
在控制台应用程序中,在 Main 函数中使用 args 参数。第一个参数是打开文件的路径。
例如:
class Program
{
static void Main(string[] args)
{
var filePath = args[0];
//...
}
}
在 WPF 应用程序中使用 Application_Startup 事件:
private void Application_Startup(object sender, StartupEventArgs e)
{
var filePath = e.Args[0];
//...
}
或使用 Enviroment 类 - 在您的 .net 应用程序中的任何地方:
string[] args = Environment.GetCommandLineArgs();
string filePath = args[0];
关于c# - 使用我的 C# 应用程序打开特定文件——例如使用 Word 打开 .doc 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13331771/