是否可以定义全系统使用的自定义URIscheme?

我一直在想,是否有可能创build一个在Windows中充当文件提供者的库。

例如,如果您尝试使用标准的打开文件对话框打开ftp://example.com/touch.txt文件,它(以某种方式神奇地)工作。 有没有办法如何实现我自己的提供者为我自己的URIscheme?

Asynchronous Pluggable Protocol可以解决吗? 我无法find一个工作代码的例子,如何使其工作。

要理解:我需要这个在系统范围内工作。 这是现在连接到互联网浏览器。

如果我需要这个File.Open("my://test.txt")工作?

File.ReadAllBytes("ftp://example.com/touch.txt"); 不起作用,如果你尝试,你会得到一个异常

 System.NotSupportedException was unhandled Message=The given path's format is not supported. Source=mscorlib StackTrace: at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.ReadAllBytes(String path) at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in D:\Code\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 25 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at WindowsFormsApplication1.Program.Main() in D:\Code\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 17 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: 

当你做一个OpenFileDialog的时候,它的工作原理是windows的秘籍,并且会先下载文件到本地的临时文件夹。 它只对ftp:http:因为OpenFileDialog是由windows shell处理的,而shell是使用URI方案的。

我相信HKCR\ftp下的“ Source Filter键指向一个注册的COM对象,该对象处理执行该本地副本的逻辑。

如果你只是希望你的应用程序打开通过像蒸汽一样的URL做的steam://rungameid/382110你只需要按照这个MSDN页面的说明。

如果你想让你的文件通过一个像http:或者ftp:这样的shell来“打开”,那么你需要编写一个充当“源代码过滤器”的COM对象,我不知道任何地方找到有关的文件。

更新 :阅读更多它看起来像你提到的异步可插入协议是如何使这些源过滤器。 我从来没有尝试过,所以我不能帮助你。