Valhalla Legends Forums Archive | .NET Platform | C# [Opening An Application]

AuthorMessageTime
hismajesty
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:
[code]      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");
      }[/code]

Any help would be appreciated.
February 17, 2004, 8:26 PM
K
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.
February 17, 2004, 8:54 PM
hismajesty
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
February 17, 2004, 8:58 PM
K
Actually, now that I look at it you should get a warning/error from this line

[code]
ShellExecute("C:\Program Files\Avant Browser\iexplorer.exe");
[/code]

It should be either:
[code]
ShellExecute(@"C:\Program Files\Avant Browser\iexplorer.exe");
// or
ShellExecute("C:\\Program Files\\Avant Browser\\iexplorer.exe");
[/code]

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.
February 18, 2004, 12:20 AM
hismajesty
Adding the '@' worked, thanks a bunch. What is the purpose behind that though?
February 18, 2004, 7:48 PM
K
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 \\.
February 18, 2004, 7:54 PM
Myndfyr
It also lets you use Newlines in constants, which is a nice feature. So, if you wanted to, you could declare:

[code]
string mySimpleHtml = @"<html>
<head>
<title>Simple HTML Literal</title>
</head>
<body>
Hello world!
</body>
</html>";
[/code]

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:

[code]
""Hello world!""
[/code]

Cheers
February 18, 2004, 8:13 PM
K
[quote author=Myndfyre link=board=37;threadid=5342;start=0#msg44903 date=1077135209]
It also lets you use Newlines in constants, which is a nice feature. So, if you wanted to, you could declare:

[code]
string mySimpleHtml = @"<html>
<head>
<title>Simple HTML Literal</title>
</head>
<body>
Hello world!
</body>
</html>";
[/code]

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:

[code]
""Hello world!""
[/code]

Cheers

[/quote]

Wow, you learn something new everyday -- I didn't know that @ sign let you put newlines in.
February 18, 2004, 10:27 PM

Search