Click here to Skip to main content
15,891,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
 StringBuilder buildHTML = new StringBuilder();
 //Creating HTML File
 buildHTML.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" +
                                "<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
                               "<head>" +
                               "<center><H2 styele=\"color: #FF5C00;\">- Report</H2></center>" +
                               "<style>" +
                               "body { font-family: \"Calisto MT\", \"Bookman Old Style\", Bookman, \"Goudy Old Style\", Garamond, \"Hoefler Text\", \"Bitstream Charter\", Georgia, serif; }" +
                               "table { border-collapse: collapse;  width: 100%; }" +
                               "th, td { padding: 0.25rem; text-align: left; border: 1px solid #000; }" +
                               "th{ background: #3B98E2; text-align: left; color: #fff; }" +
                               "tbody tr:hover { background: #A9D7FC; }" +
                               "</style>" +
                               "<title> ADAPT Report </title>" +
                               "</head><body> <table>" +
                               "<th>Sl.NO</th><th>Test</th><th>Description</th><th>Change during installation</th><th>Values Changed</th><th>Link</th>");

buildHTML.Append("</body></html>");
                StreamWriter sw = new StreamWriter(@OutputFolder + "\\" + htmlName + ".html");
                sw.WriteLine(buildHTML);
                sw.Close();
                Console.WriteLine("report created successfully");
                var proc = new Process();
                proc.StartInfo.FileName = @OutputFolder + "\\" + htmlName + ".html";
                proc.Start();
                proc.WaitForExit();
                proc.Close();


I need to open the HTML page in a browser in a windows form from my console application, so if i close the windows application the browser and the windows application close automatically.

Thanks in Advance
Posted
Updated 8-Feb-15 23:18pm
v3
Comments
Richard MacCutchan 9-Feb-15 5:44am    
OK, you have told us what you want to do but not what problems you are having.
Renjith_R 9-Feb-15 5:48am    
i don't find a method to open the HTML file dynamically in a browser in a windows form within a console application.
Richard MacCutchan 9-Feb-15 5:53am    
A Windows form is a totally different program type from a console application. You need to explain better what you are trying to do, and how these two types are supposed to interact.
Renjith_R 9-Feb-15 6:01am    
i have a console application which create a report, i need to open this HTML report in a browser. to run this application further i need to close the browser.

var proc = new Process();
proc.StartInfo.FileName = @OutputFolder + "\\" + htmlName + ".html";
proc.Start();
proc.WaitForExit();
proc.Close();

By using this i can open this in a web browser, but some time its failing when some other url is opened in the browser,at this time i need to kill the process manually , so rather by doing this i need to open this HTML report in a separate browser in a windows form application so if i close the windows form application it close the browser automatically and allow the console application to run further.

Richard MacCutchan 9-Feb-15 6:08am    
Why not do all the work in a single Windows Form application? Create the report or HTML, and use a WebBrowser control to display it. No need for a separate console application, or worrying about the browser.

1 solution

1) create a new project with winforms
2) add a control to that winforms capable of showing html pages. You need to add some reference, I believe it's called webcontrol or browsercontrol or something. Look here[^]
3) reference your winforms project in the console project and call the winforms dialog.

That way you avoid starting up seperate browser processes etc...

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900