From: Robson Felix on
Folks,

I've spent the last 3 hours fighting to get the EXACT content as being
displayed in "View Source" (as we can easily do by just accessing the
property DocumentText in the WebBrowser object). Unfortunatelly, there is no
easy way of doing this when you directly access the activex object. If you
cast axWebBrowser.Document to any HTML interface on mshtl, by any properties
you try to get the HTML source code from, the result is not consistent with
what is being presented. Sometimes tags are missing, sometimes tags are not
properly quoted, etc.The way I found to do this was:

Implement a FileSystemWatcher in the form with the following properties

..Path =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
"Content.IE5");
..Filter = "*.htm";
..IncludeSubdirectories = true;

by implementing the events Created and Changed I change a global variable on
my form with the content of FileSystemEventArgs.FullPath.

Each and everytime the browser navigates to a page, a file is generated
there with the content (when we click View Source in the browser, it just
opens the file that's already there).

Then I created a method that read the entire content of this file and I use
it wherever I need. It works perfectly.

I just thought of sharing this with the community since I didn't find
anything on this matter.

Best regards,
Robson


From: Nicholas Paldino [.NET/C# MVP] on
Robson,

I wouldn't recommend doing this, as it's roundabout, and implementation
specific. You can actually access what is returned by DocumentText without
resorting to accessing the file system.

What you should be doing is casting the instance of the document to
IPersistStreamInit (which you will have to define yourself, as it is a COM
interface). Once you have that, you can call the Save method, passing an
implementation of IStream (again, a COM interface), which will persist the
document to the stream.

Then, you can access that same stream, get the bytes (which should be
easy, since you have to implement IStream) and then convert that to a string
which you can do whatever you wish to.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp(a)spam.guard.caspershouse.com

"Robson Felix" <robson(a)robsonfelix.com> wrote in message
news:eT0PFCeSIHA.1528(a)TK2MSFTNGP04.phx.gbl...
> Folks,
>
> I've spent the last 3 hours fighting to get the EXACT content as being
> displayed in "View Source" (as we can easily do by just accessing the
> property DocumentText in the WebBrowser object). Unfortunatelly, there is
> no easy way of doing this when you directly access the activex object. If
> you cast axWebBrowser.Document to any HTML interface on mshtl, by any
> properties you try to get the HTML source code from, the result is not
> consistent with what is being presented. Sometimes tags are missing,
> sometimes tags are not properly quoted, etc.The way I found to do this
> was:
>
> Implement a FileSystemWatcher in the form with the following properties
>
> .Path =
> Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
> "Content.IE5");
> .Filter = "*.htm";
> .IncludeSubdirectories = true;
>
> by implementing the events Created and Changed I change a global variable
> on my form with the content of FileSystemEventArgs.FullPath.
>
> Each and everytime the browser navigates to a page, a file is generated
> there with the content (when we click View Source in the browser, it just
> opens the file that's already there).
>
> Then I created a method that read the entire content of this file and I
> use it wherever I need. It works perfectly.
>
> I just thought of sharing this with the community since I didn't find
> anything on this matter.
>
> Best regards,
> Robson
>

From: christery on
Aha, sooo, as a service... now I get it...

This (1:st solution) can be used to realize what your kids/wife really
are doing on the net...
eaven if they clean the computer.... by any program other than format
c: /autotest ;)

Yepp, worth 3 hours..

//CY