There is a quick way to have a companion browser come up with generated html from your application in C# and .Net. The following example simulates getting or generating the html, saving it to a file and then launching the file from the command line.

First off you will need to include these namespaces:
using System.Diagnostics;
using System.IO;
Then you can do this code.
string filename
    = string.Format(@"{0}\{1}",
                    System.IO.Path.GetTempPath(),
                    "testhtm.htm");

File.WriteAllText(filename, "<h1>Hello</h1>");

Process.Start(filename);
  • Line 02: We assume the user does not have the final slash. A more diligent programmer will check for the slash.
  • Line 06: We simply write out the html to a file.
  • Line 08: Thanks to the OS it has assigned the extension to a launchable application and htm usually goes with the default browser. By calling the static Start on the Process Class we launch the html file.
Don’t forget to delete (or attempt to delete the file) when your program closes as a courtesy.
Share