2

I'm writing code that will start a download from our company's ftp (ftp://...) but when using Process.Start("ftp://..."); Windows will prompt me for an app to open it with (I'm using Windows 10). If I use Process.Start("http://www.google.com"); it doesn't prompt. How do I avoid this prompt and just navigate the user to the ftp URL?

derekantrican
  • 1,891
  • 3
  • 27
  • 57

1 Answers1

2

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:

Community
  • 1
  • 1
rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • Ok, that makes sense. Is it possible to use the default browser to open the ftp url? Or do I have to pick one? – derekantrican Aug 08 '16 at 16:56
  • For future reference, I had to also reference this answer to get a working final product: http://stackoverflow.com/a/17599201/2246411 – derekantrican Aug 08 '16 at 18:02