4

i have a c# application, which calls an API and the response is in HTML format. i don't want to save the HTML code to a file but i want to open that html code in a browser

i am able to display if the HTML is saved in a file using

System.Diagnostics.Process.Start(pathToHtmlFile);
Sumeshk
  • 1,980
  • 20
  • 33
  • possible duplicate of [How to display the string html contents into webbrowser control?](http://stackoverflow.com/questions/5362591/how-to-display-the-string-html-contents-into-webbrowser-control) – Vivek Jain Mar 18 '14 at 06:57
  • not a duplicate question, i am using a console application and i don't want to save the html code in a file – Sumeshk Mar 18 '14 at 09:42
  • That is fine. Whether you use it in Windows Application or console application, what you're trying to achieve looks same. That's why I marked it as a duplicate. – Vivek Jain Mar 18 '14 at 11:21
  • there is no accepted answer in that and the answers are not solving my issue – Sumeshk Mar 18 '14 at 11:26

2 Answers2

3

If you want to show your html code in an external browser then you have to temporary save your code to a file and execute by the browser with Process.Start.

You can display the html code in your own Application with the WebBrowser-Control. Don't forget to use the DocumentCompleted Event to ensure that WebBrowser.Document is not null.

norbertVC
  • 425
  • 1
  • 4
  • 12
2

You may use the WebBrowser Control from your Windows Application:

WebBrowser browser = new WebBrowser();

// Navigate to URL
browser.Navigate("http://www.somesite.com");

// Set HTML code
browser.Document.Write("<html><body>...</body></html>");

// Another way to set HTML code
browser.DocumentText = "<html><body>...</body></html>";

Please use this as a starting point and not as a copy-paste solution

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47