做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:
當你做一個打開文件對話框的窗口騙子與和將文件下載到本地臨時工作原理的原因異常首先文件夾。它只對ftp:
和http:
執行此操作,因爲OpenFileDialog由Windows Shell處理,而Shell是使用URI方案的。
我相信HKCR\ftp
下的Source Filter
鍵指向一個註冊的COM對象,該對象處理執行該本地副本的邏輯。
如果您只想通過訪問網址來打開您的應用程序,就好像蒸汽一樣,它就是steam://rungameid/382110
您只需按照this MSDN page中的說明操作即可。
如果你希望你的文件是「打開」通過像http:
或ftp:
一個外殼,打開文件對話框沒有你需要寫充當「源過濾器」的COM對象,我不知道任何找到相關文檔。
更新:閱讀更多它看起來像Asynchronous Pluggable Protocol像你提到的是你如何使這些源過濾器。我從來沒有嘗試過,所以我無法幫助你。
完全可能,你在正確的軌道上。看看https://msdn.microsoft.com/en-us/library/aa767914%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 – itsme86
樣本可在這裏https:// blogs。 msdn.microsoft.com/noahc/2006/10/19/register-a-custom-url-protocol-handler/ –
好的。這使我可以在調用URI時打開我的應用程序。但是如果我想通過這個URI傳遞一個對象呢?例如File.Read( 「我://test.txt」); –