如何使用我的应用程序打开文件? [英] How do I open a file with my application?

查看:245
本文介绍了如何使用我的应用程序打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,你知道在程序如Microsoft Excel或Adobe Acrobat Reader中,你可以单击一个文件在浏览器中,它将打开与相关的程序。这就是我想要我的应用程序。现在,我知道如何在Windows中设置文件关联,以便它知道每个扩展的默认程序。我的问题是如何让我的应用程序打开文件时,我双击该文件。

Ok, you know how in programs like Microsoft Excel, or Adobe Acrobat Reader you can click on a file in explorer and it will open with the associated program. That's what I want my application to do. Now, I know how to set up the file associations in Windows so that it knows the default program for each extension. My question is how do I get my application to open the file when I double click the file.

我使用google搜索了网络,我搜索过msdn网站,我搜索了几个论坛,包括这一个,但我还没有找到任何东西解释如何完成这个。我猜它与主要方法的参数有关,但这只是一个猜测。

I've searched the web using google, I've searched the msdn site, and I've searched several forums including this one but I haven't found anything that explains how to accomplish this. I'm guessing it has something to do with the parameters of the main method but that's just a guess.

如果有人能指出我的方向,我可以从那里。先感谢您的帮助。

If someone can point me in the right direction I can take it from there. Thanks in advance for your help.

Shane

推荐答案

您需要在应用程序中读取事件args main

You need to read the event args in your applications main function in order to read the file path and be able to open it in your application.

请参阅此 a>查看如何访问 main 方法中的命令行参数。

See this and this to see how to access the command line arguments in your main method.

static void Main(string[] args)
{
    System.Console.WriteLine("Number of command line parameters = {0}", args.Length);

    foreach (string s in args)
    {
        System.Console.WriteLine(s);
    }
}

这篇关于如何使用我的应用程序打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆