AxSHDocVw.AxWebBrowser Component Question

  • Thread starter Thread starter Michael C
  • Start date Start date
M

Michael C

Hi all,

Quick question about the AxSHDocVw.AxWebBrowser Component. I was wondering
if there is a way to view pages generated internally within my application
without writing them to disk. For instance, I'd like to do something like
the following:

string page = "<HTML><BODY>This is a test.</BODY></HTML>";

And display the page variable's contents in the AxWebBrowser (without
writing to disk and using the .Navigate() method to re-load the file.) Any
help is appreciated.

Thanks,
Michael C., MCDBA
 
Hello Michael,
string page = "<HTML><BODY>This is a test.</BODY></HTML>";

And display the page variable's contents in the AxWebBrowser (without
writing to disk and using the .Navigate() method to re-load the file.)
I had the same problem in the past.
My solution is to write the file in the system temp directory.

System.IO.Path.GetTempFileName()
returns a uniquely named zero-byte temporary file on disk and returns the full path to that file that you can write.
After write the html code, you can pass this path to the .navigate method.
Remember to delete this file when you close the application.
Any help is appreciated.
I Hope thaht this help you.

Bye
 
Thanks Mighell,

But that solution requires "writing to disk and using the .Navigate() method
to re-load the file." I've found another solution that works without
creating a file, some of the code is on the MS Website, the rest is borrowed
from Stefan Popov.

It works like this:

// dummy ref objects for Navigate call to about:blank
object Zero = 0;
object EmptyString = "";
// HTML to display
string aString = "<HTML><BODY>This is a test</BODY></HTML>";
// Have to navigate to about:blank first, or axWebBrowser1.Document will be
null
axWebBrowser1.Navigate("about:blank", ref Zero, ref EmptyString, ref
EmptyString, ref EmptyString);
// Create an IHTMLDocument2
IHTMLDocument2 doc = axWebBrowser1.Document as IHTMLDocument2;
// Write the HTML to the doc
doc.writeln(aString);
// Close the doc
doc.close();

Thanks anyway,
Michael C., MCDBA

Mighell said:
Hello Michael,
I had the same problem in the past.
My solution is to write the file in the system temp directory.

System.IO.Path.GetTempFileName()
returns a uniquely named zero-byte temporary file on disk and returns the
full path to that file that you can write.
 
My issue is related to this. I have no problem getting the following
code to work when it is embeded in a class that contains the Main
method (i.e. a form that starts up when you run the application).
However, the way my application runs, there are many screens prior to
the web brower form showing. For some reason, if I don't call the web
browser form as the startup object - nothing ever populates in the
browser. It will if it is the startup and won't if it's not. Other
info - the form is a mdi child...

This is getting extremely frustrating. Any help is much appreciated!!!
 
Back
Top