如何获取用于启动程序的关联文件的路径?
我有一个具有关联文件类型的程序。但是,当我双击文件启动程序时,我无法弄清楚该路径传递给程序的位置。
最初我以为文件路径会在Environment.CommandLine中,但命令行只包含程序路径。
我使用 Visual Studio 中的发布选项指定了文件关联,如下所示:扩展名:.ext,描述:某些文件,ProgId:项目名称,图标:SomeIcon.ico。
I have a program with an associated file type. However, when I double-click a file to launch the program, I can't figure out where that path was passed to the program.
Initially I thought the file path would be in Environment.CommandLine, but the command line only contained the program path.
I specified the file association using the Publish Options in visual studio like so: extension: .ext, Description: Some File, ProgId: ProjectName, Icon: SomeIcon.ico.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是对的,它确实应该作为命令行参数传递,并可以通过Environment.CommandLine使用。
我的猜测是文件关联本身有问题。 这里是一篇关于这些东西如何工作的过时但仍然有用的 TechNet 文章。特别是下面截图中的
“%1”
是必不可少的。我是不确定 DDE 的情况,所以如果您不使用它,请将其关闭。
You are right, it should indeed be passed as a command line argument and be available through
Environment.CommandLine
.My guess is that something is wrong with the file association itself. Here is a dated but still useful TechNet article on how these things work. In particular, the
"%1"
in the screenshot below is essential.I'm not sure about the DDE thing, so if you're not using it, turn it off.
据猜测,您的文件类型关联可能配置不正确。如果您在注册表中查找文件类型的“打开”命令,该命令可能配置为“c:\your-company\your-app.exe”,而不是“c:\your-company\your-app.exe” -app.exe" "%1",如果您希望文件路径显示在命令行上,则需要使用该名称。
As a guess, your file type association may not be configured properly. If you look in the registry at your "Open" command for your file type, the command is probably configured as "c:\your-company\your-app.exe", instead of as "c:\your-company\your-app.exe" "%1", which is what it would need to be if you wanted the file path to show up on the command line.