直接打开文件

发布于 2024-08-29 06:12:36 字数 122 浏览 4 评论 0原文

我用 C# 创建了一个文本编辑器,并为我的程序使用的 XML 文件使用了特殊的文件扩展名。当我从 Windows 上下文菜单中使用“打开方式...”时,我的程序无法读取该文件,并且出现错误。

我该如何解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

关于从前 2024-09-05 06:12:36

Main() 方法中,您需要捕获文件名:

static void Main(string args[])
{
   string fileName;
   if (args.Length > 0)
      fileName = args[0];

   ...
}

然后您需要将 fileName 传递给打开文件的代码。如何做到这一点取决于您。

如果您的 Main() 方法没有参数,只需添加 string args[] 参数,运行时将负责使用命令行参数填充数组。

如果您已经这样做了,那么这可能是一个超级用户问题。

In your Main() method, you need to capture the file name:

static void Main(string args[])
{
   string fileName;
   if (args.Length > 0)
      fileName = args[0];

   ...
}

Then you'll need to pass fileName to the code that opens the file. How you do that is up to you.

If your Main() method has no parameters, just add the string args[] parameter and the runtime will take care of populating the array with the commandline parameters.

If you are already doing that, then this is probably a SuperUser question.

蝶舞 2024-09-05 06:12:36

但 Main 就像它

static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

没有任何参数

but the Main like that

static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

it doesn't have any parameters

忆梦 2024-09-05 06:12:36

您可以使用这个简单的代码来回答我

   private void button1_Click(object sender, EventArgs e)
    {
        richTextBox1.Text = File.ReadAllText(@"d:\wifi.txt");
    }

在 richtextbox1 中查看的文本

you can use this simple code to answer me

   private void button1_Click(object sender, EventArgs e)
    {
        richTextBox1.Text = File.ReadAllText(@"d:\wifi.txt");
    }

the text viewed in the richtextbox1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文