0

I am currently creating a winforms project and we have returned an html string from some method and now want to load it into the WebBrowser.

I know I can use the

WebBrowser.Document.Write()

to write html text to Webbrowser.

But my production environment doesn't allow me to do that.

The alternative is to try to navigate it to a temporary html file using

WebBrowser.Navigate(@"temp file location")

What I'm asking is:

For security reasons, redundant temporary files are not allowed in production environment.

Is there any way to skip the step of creating a temporary file?

Trying to find a way to implement it using Navigate.

大陸北方網友
  • 3,696
  • 3
  • 12
  • 37
  • You can set the DocumentText property of the WebBrowser control to a string. Already answered here https://stackoverflow.com/questions/4467219/c-sharp-webcontrol-how-to-load-a-html-on-the-fly and here https://stackoverflow.com/questions/5362591/how-to-display-the-string-html-contents-into-webbrowser-control – Wh1t3rabbit Jun 01 '23 at 06:31

1 Answers1

0

How have they restricted webBrowser.Document.Write() in production?

Can you access webBrowser.DocumentText = html;?

Also you could try:

string html = "Your HTML Here";
string dataUrl = "data:text/html;charset=utf-8," + Uri.EscapeDataString(html);
webBrowser.Navigate(dataUrl);
Andy Wynn
  • 1,171
  • 7
  • 11