views:

230

answers:

1

I need to use OpenFileDialog to input a URI or local path. The problem is that the schema of the URL is not something windows knowns about (or should know about because it's a hack for testing).

I can turn off all validation and as long as I don't feed it a invalid chars it returns but then it will happily eat anything else and that isn't what I want either.

What I want is for it to accept valid local paths and correctly formatted URI's without validating the schema component of the Uri, that is the http, ftp or whatever at the start.


My current code is:

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 feed the dialog foo://127.0.0.1/foo it runs file to the last line and crashes with "The given path's format is not supported."

Why is it still trying to validate stuff?

A: 

I assume you're talking about C#/.NET since you refer to it as an "OpenFileDialog".

What I assume you would need to do is subclass the dialog itself (It is, afterall, a Win32 Dialog). Unfortunately I don't have the knowledge on how to do it, but hopefully it pushes you in the right direction.

Marineio