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?
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:
Related
I am trying to make a phone call from .Net console Application using Jabber client installed on my laptop.
I want to achieve something similar that you would achieve by the following anchor command in HTML:
Weekly conference call
I want to run the same command through my console application so that it launches Jabber and make a call.
I am not familiar with Jabber, but most likely the client has registered the CISCOTELCONF protocol (similar to how HTTP is registered to your default browser and MAILTO might open Outlook). Therefore you should be able to use Process.Start to pass the same URL to the shell, where it can decide what to do - hopefully invoking the Jabber client as it would if you clicked on the link. You can test this by copy-and-pasting the URL into Start-Run. If it works, then this should also.
var startInfo = new ProcessStartInfo("CISCOTELCONF:msmith#domain;amckenzi#domain")
{
UseShellExecute = true
};
Process.Start(startInfo);
Note the default for UseShellExecute is true, so you do not actually need this line. I've included it anyway because this is what causes Process.Start to, well, invoke the OS shell.
I have an IE plugin which adds buttons in a page where there are pdf links and opens them in a specific application when clicked.
Lets say I need to open a xyz.pdf file in abc.exe application. abc is not the default application for file type .pdf.
In one machine the below works
Process p = Process.Start("pathtoabc.exe", "pathtoxyz.pdf");
In another machine it only works if I make abc.exe as the default app and then use the below
Process p = Process.Start("pathtoxyz.pdf");
Can you give me any pointers please? I also tried using ProcessStartInfo with no change
Updates:
I tried using the default Acrobat reader with an argument
Argument for processstartinfo looks like this "C:\PDF Files\Professional-Letters-Guide.pdf"
FileName = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
Result - Acrobat reader opens but with an error message "File not found". The is available in the path though.
Solved:
It was a space in the Foldername.. solved it by enclosing the filename with quotes "\""
Thank you all for the suggestions.. they helped me think it through.
Have you tried qualifying the Process.StartInfo.Arguments value with quotes and the full path to the file? What about the WorkingDirectory property? Also, the previous assertion regarding confirmation of the application being called supporting command line parameters is absolutely valid. You can be fooled into thinking that it does due to operating system file extension associations specific to a machine.
The second parameter of the Process.Start is passed to the application you are trying to start and it wont open the file using this application "pathtoabc.exe" unless the application "pathtoabc.exe" accepts the file name as a startup argument.
So you need to check if the application you are trying to use supports this kind of argument.
I could not find any information about this. I am sure there is a term for this type of applications, but I have no idea where to look. That's why I decided to ask here.
So there are a few websites where you hover over a link or button it says something like application:xyz where application usually is the name application to run, and the xyz are the parameters or something.
An example is all the torrent links. If you hover over a link there it says
magnet:?somethingxxxxxxxxxxxx how can I bind my own custom application to a certain URL?
Let's say I have a C# application I call Musiclist. I want to make URLs like: musiclist:?song=hey123
And when I click it in my browser, it opens the application.
I really could not find anything about this with some examples, or how I pass those variables in with the :? in the link, so that's why I cannot provide any code examples.
This is what's called a protocol or a URI Scheme.
This is defined in the registry, so you'd have to add the correct values there:
HKEY_CLASSES_ROOT
<protocol>
(Default) = "URL:<protocol name>"
URL Protocol = ""
DefaultIcon
(Default) = "<path to your application>,<icon index>"
shell
open
command
(Default) = "<path to your application>" "%1"
In your case this could for example be:
HKEY_CLASSES_ROOT
musiclist
(Default) = "URL:Music list protocol"
URL Protocol = ""
DefaultIcon
(Default) = "C:\Program Files\Musiclist\musiclist.exe,0"
shell
open
command
(Default) = "C:\Program Files\Musiclist\musiclist.exe" "%1"
Everything after the colon (:) will be passed to your application as (a) Command Line Argument(s).
I have a requirement to open a windows explorer Path like this "C:\New Folder\" or "http:\gmail.com" using C# code. Actually, once the user types the link\path in the text box and save it, a link should appear and on clicking the link, the required folder path or link should open. My requirement is satisfied with Process.Start(). But, Process.Start is not working in IIS. Can any one suggest any other options. Please.
The code am using is below.
string myPath = #"c:\backoffice";
System.Diagnostics.Process prc = new System.Diagnostics.Process();
prc.StartInfo.FileName = myPath;
prc.Start();
You are misunderstanding the way the web works. If you call Process.Start on the web server, it runs that command on the web server. There is no way that the Process.Start is magically mapped to some action on the client.
Also, you can't just open a specific folder on the client machine from a web site. The security protocols implemented in the browser will prevent that.
As the title says, it is possible to launch Download Manager (such as Orbit) passing the URL of the file to download?
Edit:
How can I check how those programs are expecting the url???
What parameters are needed to be passed ??
My problem is , I do NOT know how those programes are expecting their inputs.
Before that, I also would like to check if one of download managers has installed in the machine.
If you want to start an application from C# you can create a new process of the .exe file of the application and if that application supports arguments you can add them also. So you will need to find out if Orbit accepts arguments. The example below shows how to start a new process with arguments. Please note that the application will start out of the process of your own application.
string args = " \"" + URL + "\"";
ProcessStartInfo psi = new ProcessStartInfo("path to Orbit", args);
Process p = Process.Start(psi);
string path = #"C:\Program Files\Orbit\Orbit.exe";
string arg = #"http://www.example.com/file.ext";
System.Diagnostics.Process.Start(path, arg);
There is no way to find an abstract downloader on a computer and launch it directly to download a file.
Only one idea I have - launch a browser and hope it will download file by itself or launch a registered downloader:
Process.Start("http://example.com/file.ext");
If the download manager accepts url arguments then you can start a process and pass the desired URL to it
Process.Start("Orbit.exe -http://www.something.com/file.ext");
So this approach highly depends on the download manager.
I guess it is kind of depends in the download manager.
If it has support for command line arguments with the file location URL then you can use the System.Diagnostics.Process class.