I'm trying to make a browser selector, allowing me to choose which browser to use since I sometimes switch. However, I have only gotten it to work for IE and not for Avant Browser. It continues to open IE even when calling Avant.
Here is my current coding:
public static void ShellExecute(string file)
{
Process p = new Process();
p.StartInfo.FileName = file;
p.Start();
}
private void button1_Click(object sender, System.EventArgs e)
{
ShellExecute("IEXPLORE.EXE");
}
private void button2_Click(object sender, System.EventArgs e)
{
ShellExecute("C:\Program Files\Avant Browser\iexplorer.exe");
}
Any help would be appreciated.
Doesn't seem to be anything wrong with your code. Check the filenames (\Avant Browser\iexplorer.exe?) I don't use it so I'm not sure if the r is there or not. You know you can open the default browser by simply starting a process with a http:// destination, if that will help at all.
Nope, the filename is correct. I wanted to create this so I can choose which browser to use (ither IE or Avant) without having to click on the IE icon (on desktop) or the Avant icon (in the start menu.) More of a feature to aid in my laziness. :P
Actually, now that I look at it you should get a warning/error from this line
ShellExecute("C:\Program Files\Avant Browser\iexplorer.exe");
It should be either:
ShellExecute(@"C:\Program Files\Avant Browser\iexplorer.exe");
// or
ShellExecute("C:\\Program Files\\Avant Browser\\iexplorer.exe");
It's possible that this is the cause of your error, but I don't think \P is a valid escape code, so the compiler should have choked.
Adding the '@' worked, thanks a bunch. What is the purpose behind that though?
It doesn't interpret escape characters. For example "\r\n" is a carriage and line feed. \a will play the alert sound when output to the console. \t will display a tab. So to put a backslash in a string, you need to escape it: \\. The @ sign means to not process the string for escape charcters, so you can simply type \ instead of \\.
It also lets you use Newlines in constants, which is a nice feature. So, if you wanted to, you could declare:
string mySimpleHtml = @"<html>
<head>
<title>Simple HTML Literal</title>
</head>
<body>
Hello world!
</body>
</html>";
Remember, though, when you want quotes within an absolute string (one with the @ preceding it), you need to use double quotes. For example, if I wanted to put "Hello world!" there, it would be:
""Hello world!""
Cheers
Quote from: Myndfyre on February 18, 2004, 02:13 PM
It also lets you use Newlines in constants, which is a nice feature. So, if you wanted to, you could declare:
string mySimpleHtml = @"<html>
<head>
<title>Simple HTML Literal</title>
</head>
<body>
Hello world!
</body>
</html>";
Remember, though, when you want quotes within an absolute string (one with the @ preceding it), you need to use double quotes. For example, if I wanted to put "Hello world!" there, it would be:
""Hello world!""
Cheers
Wow, you learn something new everyday -- I didn't know that @ sign let you put newlines in.