• Welcome to Valhalla Legends Archive.
 

C# [Opening An Application]

Started by hismajesty, February 17, 2004, 02:26 PM

Previous topic - Next topic

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:
      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.

K

#1
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.

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

K

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.

hismajesty

Adding the '@' worked, thanks a bunch. What is the purpose behind that though?

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 \\.

MyndFyre

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
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

K

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.