derekantrican derekantrican - 1 year ago 133
C# Question

Process.Start for ftp:// prompts for app

I'm writing code that will start a download from our company's ftp (

) but when using
Windows will prompt me for an app to open it with (I'm using Windows 10). If I use
it doesn't prompt. How do I avoid this prompt and just navigate the user to the ftp URL?

Answer Source

Windows knows what to do with a URL that starts with http: open the default web browser and browse to that URL. However, it doesn't natively know what to do with a URL that starts with ftp.

When you're using Process.Start, think of it like running a command from the "run" line in Windows. You usually need to specify an executable to run, and any additional information -- i.e. arguments to the executable -- occur after the path or executable name.

In this case, I'd say you just want to start Internet Explorer and provide it your URL as an argument:

var psi = new ProcessStartInfo(Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Internet Explorer\iexplore.exe"), url);
var proc = Process.Start(psi);

EDIT: to answer your question about using the default browser, see this SO answer about how to get the default browser's path:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download