I created a text editor in C# and I use a special file extension for the XML file that my program uses. When I use "Open With..." from the Windows context menu, my program doesn't read the file and I get an error.
How do I fix this?
I created a text editor in C# and I use a special file extension for the XML file that my program uses. When I use "Open With..." from the Windows context menu, my program doesn't read the file and I get an error.
How do I fix this?
在您的Main()
方法中,您需要捕获文件名:
static void Main(string args[])
{
string fileName;
if (args.Length > 0)
fileName = args[0];
...
}
然后你需要传递fileName
给打开文件的代码。你如何做到这一点取决于你。
如果您的Main()
方法没有参数,只需添加string args[]
参数,运行时将负责使用命令行参数填充数组。
如果您已经这样做了,那么这可能是一个超级用户问题。
但主要是这样
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
它没有任何参数
你可以用这个简单的代码来回答我
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = File.ReadAllText(@"d:\wifi.txt");
}
在richtextbox1 中查看的文本