views:

144

answers:

2
s += "<p style=\"text-align: left;\"><a href=\"javascript:window.print()\">PRINT</a></p>";
System.IO.File.WriteAllText(@"CheckForm.html", s);
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "explorer.exe";
startInfo.Arguments = "CheckForm.html";
System.Diagnostics.Process.Start(startInfo);

I'm having a trouble when I tried to open my C# windows application in Windows 7 otherwise there is no problem.

I couldn't open explorer.exe in Windows 7 with above code.

Any suggestions?

+2  A: 

To open an HTML file, you should simply call Process.Start with the path to the file, like this:

Process.Start(@"CheckForm.html");

This will open the file in the default program. (Typically IE or Firefox)

SLaks
but it worked well in ie6 and before. or firefox or chrome
sml
It was still wrong.
SLaks
+1, however, just an additional remark: This works only if `startInfo.UseShellExecute` (http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx) is set to `true`, which luckily is the default, so in the sample above you don't have to worry.
0xA3
So what should be the working one ?System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();startInfo.FileName = "explorer.exe";startInfo.Arguments = "CheckForm.html";System.Diagnostics.Process.Start(startInfo);StartInfo.UseShellExecute = false;this one ?
sml
You should write `Process.Start(@"CheckForm.html");`
SLaks
+1  A: 

explorer.exe is the Windows Explorer or desktop system. You probably want to open the Internet Explorer, which process name would be iexplore.exe.

Windows Explorer was previously integrated with Internet Explorer, so that – depending on the path you enter – the program switches to the wanted application. IE for urls, and Windows Explorer for local paths. That's probably why it worked before.

However with Vista I think, the integration was loosened, so this won't work any longer.

poke
explorer.exe also is the shell. So there is nothing wrong with the sample code posted by @sml.
0xA3
Yeah, explorer plays a lot of roles. But still from the code it rather seems he wants to open Internet Explorer, and not the default application for html files.
poke
Well, from the comments it seems that he wants IE, but from the code he will get the application that is associated with .html files.
0xA3
Well my answer is based on the idea that he mixed up explorer with iexplore :P
poke
Using `ieplore.exe` however requires passing a full path as argument, i.e. `startInfo.Arguments = Path.Combine(Directory.GetCurrentDirectory(), "CheckForm.html");`
0xA3
Oh, yeah, you're right! Well, whatever then :P
poke