Free Support Forum -

Display output in WinForms WebBrowser component


In version 19 we used the following method:

ViewerHtmlHandler handler = new ViewerHtmlHandler();
List<PageHtml> pages = handler.GetPages(stream, path, options);
foreach (var page in pages)
   webBrowser1.DocumentText += page.HtmlContent;

In version 20 API has changed so we are trying to do it this way:

List<MemoryStream> pages = new List<MemoryStream>();
MemoryPageStreamFactory pageStreamFactory = new MemoryPageStreamFactory(pages);
var options = HtmlViewOptions.ForEmbeddedResources(pageStreamFactory);
foreach (var page in pages)
   page.Seek(0, SeekOrigin.Begin);
   var sr = new StreamReader(pages);
   webBrowser1.DocumentText += sr.ReadToEnd();

But it does not work. Probably because we don’t have PageHtml object here and just writing whole page content is not the same as writing HtmlContent of page was.
How can we achieve this in the new version? We basically need to display content of any converted document in WebBrowser from memory, without saving locally first.

1 Like


Please have a look at this documentation article. You’ll see how to get output stream when viewing a document and later you can display content in WebBorwser from output stream. Please let us know if it helps.