How to get OpenFileDialog to accept "valid" URIs

I need to use OpenFileDialog

to enter URI or local path. The problem is that the url scheme is not something that is known about (or should know about it, because this is a hack for testing).

I can turn off all checks and as long as I don't feed him the invalid characters it returns, but then he'll happily eat something else and that's not what I want.

I want it to take the correct local paths and format the URI correctly without checking the Uri schema component, that is http

, ftp

or something at the beginning.


My current code:

var dialog = new System.Windows.Forms.OpenFileDialog();

dialog.CheckFileExists = false;
dialog.CheckPathExists = false;
dialog.ValidateNames = false;

var result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
    return dialog.FileName;

      

If I submit a dialog foo://127.0.0.1/foo

it runs the file on the last line and crashes " The given path format is not supported.

"

Why is he still trying to check the material?

+1


a source to share


1 answer


I am assuming you are talking about C # /. NET because you refer to it as "OpenFileDialog".



I am guessing that you will need to subclass the dialog itself (this is a Win32 dialog after all). Unfortunately I don't know how to do this, but hopefully it nudges you in the right direction.

0


a source







All Articles