简体   繁体   English

如何以编程方式自动从Windows资源管理器中打开文件

[英]How do I automate the opening of a file from Windows Explorer programmatically

I am writing an application that includes processing of files of a custom file format but would like to associate with my application such that when a supported file is double clicked on in Windows Explorer it can automatically calls my application's open event. 我正在编写一个应用程序,其中包括处理自定义文件格式的文件,但希望与我的应用程序关联,以便在Windows资源管理器中双击支持的文件时,它可以自动调用我的应用程序的open事件。

Please note the application is a .NET application. 请注意,该应用程序是.NET应用程序。 If you could point me to a reference I need to add or a class I have missed please let me know. 如果您可以指出需要添加的参考文献或错过的课程,请告诉我。

You probably know, that associating a double click with LAUNCHING an application is relatively easy. 您可能知道,将双击与启动应用程序相关联相对容易。 If not, here is a good SO answer . 如果没有, 这是一个很好的答案

The problem is, you don't want to LAUNCH a new application, rather raise an event in an existing one. 问题是,您不想启动一个新应用程序,而是在一个现有应用程序中引发一个事件。 Well, I don't know if there is a direct way for that, but you could write a small console executable, associate THAT with the file type, and in that application fire off a call to your main one (I'm thinking WCF Named Pipes would be the easiest to use), and at startup of your main application start listening to the pipe. 好吧,我不知道是否有直接的方法,但是您可以编写一个小的控制台可执行文件,将THAT与文件类型相关联,然后在该应用程序中触发对您的主要文件的调用(我在想WCF命名管道将是最容易使用的),并且在主应用程序启动时开始监听管道。 If a message comes in (containing the path of the file, most likely), raise the internal Open event of your application, with whatever information passed as parameter. 如果出现一条消息(很可能包含文件的路径),则使用任何传递为参数的信息引发应用程序的内部Open事件。

Hope this helps. 希望这可以帮助。

You might want to look here for how to handle single instance: 您可能想在这里查看如何处理单个实例:

https://codereview.stackexchange.com/a/25667 https://codereview.stackexchange.com/a/25667

Associating filetype with application is pretty easy as well, and you can even have your application do the association on first run. 将文件类型与应用程序关联起来也非常容易,甚至可以让您的应用程序在首次运行时进行关联。

Associate File Extension with Application 将文件扩展名与应用程序关联

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式在Windows 7中的Windows资源管理器中打开“库”文件夹? - How do I programmatically open the “Libraries” folder in Windows Explorer in Windows 7? 如何以编程方式复制在Windows下锁定的文件或文件夹? - How do I copy a file or folder that is locked under windows programmatically? 从 .Net 解决方案资源管理器中拖放时,如何以编程方式获取文件名? - How do you programmatically get the file name when dragging and dropping from .Net Solution explorer? 将文件拖放到 wpf/C# 应用程序时,如何在 Windows 资源管理器中维护文件顺序? - How do I maintain the file order in Windows Explorer when drag and dropping files into wpf/C# application? 如何以编程方式重新启动 Windows 资源管理器进程 - How to programmatically restart windows explorer process 如何以编程方式创建Windows窗体? - How do I programmatically create a windows form? 如何打开 windows 资源管理器 window 并选择特定文件夹 - How do I open a windows explorer window with a specific folder selected 如何使用.net在Windows资源管理器中预选文件? - How can I preselect a file in windows explorer using .net? 如何获取“文件资源管理器”打开的窗口的目录? - How can i get the directories of File Explorer opened windows? 在Metro应用程序中从Windows资源管理器打开文件 - Opening files from Windows Explorer in my Metro App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM