且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#CF:如何使用我的程序打开特定的文件扩展名

更新时间:2022-11-28 11:51:45

您是否更改了静态void ()方法为
did you change the static void Main() method to
[MTAThread]
static void Main(string[] args)
{
Application.Run(new Form1());
}



注意Main方法的签名。
解释如果你没有:
args参数将包含用户想要打开的文件名(包括路径),就像用参数执行你的应用程序一样。因此,如果用户单击文件"\storage card \ folder1 \ file.xyz",您的应用程序将以
" MyApplication.exe \storage card \ folder1 \ file.xyz"执行。你可以通过访问args数组的元素0来获取文件名

notice the signature of the Main method. explaination in case you didn't: the args parameter will contain the file name that the user want's to open (including the path), it's like executing your application with parameters. so if the user clicks the file "\storage card\folder1\file.xyz" your application will be executed as "MyApplication.exe \storage card\folder1\file.xyz" and you can get the file name by accessing the element 0 of the args array

string FileName = args[0];



确保在尝试查询之前检查参数可用性。使用args.getUpperBound()。

 

make sure you check for the parameter availablility before you try to query it. use args.getUpperBound().

 

希望这会有所帮助。