获取路径+这与我的应用程序打开的文件的文件名 [英] Get path+filename of file that was opened with my application

查看:132
本文介绍了获取路径+这与我的应用程序打开的文件的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#一个业余,我一直无法找到这个问题的答案。
也许我不知道正确的术语来使用。

I'm an amateur at c# and I've been unable to locate the answer to this. Perhaps I am not aware of the correct terms to use.

当视频文件拖放到我的EXE应用程序,我想申请知道它用一个文件推出,能够知道该文件的路径和文件名。这种方式,用户不必使用文件>打开菜单

When a video file is dragged onto my exe application, I would like the application to know that it was launched with a file and be able to know the path and filename of that file. This way, the user does not have to use the file>open menu.

希望是很有意义的。
谢谢

Hope that makes sense. Thanks

推荐答案

您可以检查哪些被用来启动应用程序的命令行参数。
。如果您的应用程序通过在.exe文件删除一个文件启动,将有一个命令行参数的文件的路径。

You can check the command line arguments which were used to launch the application. If your application was started by dropping a file on the .exe file, there will be a single command line argument with the path of the file.

string[] args = System.Environment.GetCommandLineArgs();
if(args.Length == 1)
{
    // make sure it is a file and not some other command-line argument
    if(System.IO.File.Exists(args[0])
    {
        string filePath = args[0];
        // open file etc.
    }
}

你的问题标题状态,你想要的路径和文件名可以使用获取文件名:

As your question title states, you want the path and the file name. You can get the file name using:

System.IO.Path.GetFileName(filePath); // returns file.ext

这篇关于获取路径+这与我的应用程序打开的文件的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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