Open New Browser on Error

  • Thread starter Thread starter Tim Cowan
  • Start date Start date
T

Tim Cowan

Hi
I have the following code to write an error file and it is supposed to open
the HTML file in a browser when an error occurs. It creates the file Ok but
doesn't open the new browser and doesn't give me any errors.

Tim

FileStream file = new FileStream(@"C:\errors\error.htm",
System.IO.FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(file);
sw.Write(strHtml.ToString());
System.Diagnostics.Process.Start(@"C:\errors\error.htm");
sw.Close();
file.Close();
 
Try closing the file before you start the browser.

You may also need to use sw.Flush();

sw.Close();
file.Close();
System.Diagnostics.Process.Start(@"C:\errors\error.htm");
 
I tried that Jim, both with and without sw.Flush(), but still no luck. Any
other ideas?
 
Does typing C:\errors\error.htm from a command prompt work?

The following code works fine on my system.

private void Form1_Load(object sender, System.EventArgs e)

{

String strHtml = "<html><body>Testing</body></html>";

FileStream file = new FileStream(@"C:\errors\error.htm",

System.IO.FileMode.OpenOrCreate);

StreamWriter sw = new StreamWriter(file);

sw.Write(strHtml.ToString());

System.Diagnostics.Process.Start(@"C:\errors\error.htm");

sw.Close();

file.Close();

}
 
I can open it from the command line but in the code it doesn't work. I am
running a C# web application in debug mode - would this make any difference?

Tim
 
Yes that would make a huge difference!

Web applications don't interact with the server desktop and therefore won't
launch the browser at the server.

If you are trying to use Process.Start on the client's browser, that won't
work either because of security.

The C# code is running inside of IIS at the server, not the client.

To open the error log in the browser:

Either use Response.Redirect to a server url that contains your error log

Or

Do a Resonse.Write of the file contents.

Or

use Javascript to do a window.open(errorurl)
 
Thanks Jim,

I am going to try that.

Tim

Jim Hughes said:
Yes that would make a huge difference!

Web applications don't interact with the server desktop and therefore
won't launch the browser at the server.

If you are trying to use Process.Start on the client's browser, that won't
work either because of security.

The C# code is running inside of IIS at the server, not the client.

To open the error log in the browser:

Either use Response.Redirect to a server url that contains your error log

Or

Do a Resonse.Write of the file contents.

Or

use Javascript to do a window.open(errorurl)
 
Back
Top