Doing File.ReadAllBytes("ftp://example.com/touch.txt");
funktioniert nicht, wenn Sie es versuchen erhalten Sie eine Ausnahme wie
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:
Der Grund, es funktioniert, wenn Sie tun, ein Openfile Fenster betrügt mit dem ist, und wird die Datei in einen lokalen temporären Download Ordner zuerst. Es tut dies nur für ftp:
und http:
, weil OpenFileDialog von der Windows-Shell behandelt wird und die Shell URI-Schemata verwendet.
Ich glaube, der Schlüssel unter HKCR\ftp
verweist auf ein registriertes COM-Objekt, das die Logik dieser lokalen Kopie verarbeitet.
Wenn Sie nur möchten, dass Ihre Anwendung geöffnet wird, indem Sie zu einer URL gehen, wie Steam es mit steam://rungameid/382110
tut, müssen Sie nur den Anweisungen in this MSDN page folgen.
Wenn Sie Ihre Datei „geöffnet werden kann“ über eine Shell wie http:
oder ftp:
nicht mit dem Datei-Dialog sein, müssen Sie ein COM-Objekt schreiben, die als „Source Filter“ wirkt, ich weiß nicht, irgend Ort, um die Dokumentation zu finden.
Update: Lesen mehr es sieht aus wie Asynchronous Pluggable Protocol wie Sie erwähnt, ist, wie Sie diese Quellfilter machen. Ich habe nie versucht, eins zu machen, also kann ich dir darüber hinaus nicht helfen.
Völlig möglich und Sie sind auf dem richtigen Weg. Werfen Sie einen Blick auf https://msdn.microsoft.com/en-us/library/aa767914%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 – itsme86
Ein Beispiel ist hier verfügbar https: // Blogs. msdn.microsoft.com/noahc/2006/10/19/register-a-custom-url-protocol-handler/ –
OK. Dadurch kann ich meine Anwendung öffnen, wenn der URI aufgerufen wird. Aber was, wenn ich ein Objekt über diesen URI liefern möchte. z.B. Datei.Lesen ("my: //test.txt"); –