Displaying HTML from memory

T

Tomaz Koritnik

Hi

I have many short HTML files stored in a binary stream storage to display
descriptions for various items in application. HTML would be display inside
application using some .NET control or COM control (like Microsoft
WebBrowser). For each description there is one HTML file and along
description text, it contains links to related information. Clicking related
information would for example open new form in application and display some
list of items from DB.

When I load HTML data from stream storage, it is stored in memory inside
memory stream. I could display HTML data by first saving memory stream
contents in a temporary file and then instruct browser control to load from
that file, but I absolutely don't want to use temporary files in this
process. I want to display HTML data directly from the memory stream (or
some other form of memory storage). Is there any control available for C#
that can display HTML data directly from memory?

regards
Tomaz
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Tomaz Koritnik,

The web browser expects an URL that could be a file or a URL for a internet
resource that is served by some web server. There is no way that you can
pass a memory stream. Of course it depends on the web browser control. If
you use some special control that accepts that then go for it. If you are
using control like IE what you can do is to create a simple ASP.NET
application with a single page. This page can read the name of the web page,
you want to display, as a parameter. The ASP.NET page then can read the
stream and flush its contents to the HttpRespond.Output stream.

For this solution though you need IIS running on the machine. However,
easiest solution would be to save the stream in a file and point the borwser
to it.

HTH
Stoitcho Goutsev (100) [C# MVP]
 
T

Tomaz Koritnik

Hi

Thanks but I know that IE browser does not support displaying HTML files
from memory. IIS is out of the questione and I still don'w want to save HTML
to temporary file :). That's why I'm trying to find some other HTML
displaying component that can do this because I don't know if there are any.
Do you know?

regards
Tomaz

Stoitcho Goutsev (100) said:
Tomaz Koritnik,

The web browser expects an URL that could be a file or a URL for a
internet resource that is served by some web server. There is no way that
you can pass a memory stream. Of course it depends on the web browser
control. If you use some special control that accepts that then go for it.
If you are using control like IE what you can do is to create a simple
ASP.NET application with a single page. This page can read the name of the
web page, you want to display, as a parameter. The ASP.NET page then can
read the stream and flush its contents to the HttpRespond.Output stream.

For this solution though you need IIS running on the machine. However,
easiest solution would be to save the stream in a file and point the
borwser to it.

HTH
Stoitcho Goutsev (100) [C# MVP]


Tomaz Koritnik said:
Hi

I have many short HTML files stored in a binary stream storage to display
descriptions for various items in application. HTML would be display
inside
application using some .NET control or COM control (like Microsoft
WebBrowser). For each description there is one HTML file and along
description text, it contains links to related information. Clicking
related
information would for example open new form in application and display
some
list of items from DB.

When I load HTML data from stream storage, it is stored in memory inside
memory stream. I could display HTML data by first saving memory stream
contents in a temporary file and then instruct browser control to load
from
that file, but I absolutely don't want to use temporary files in this
process. I want to display HTML data directly from the memory stream (or
some other form of memory storage). Is there any control available for C#
that can display HTML data directly from memory?

regards
Tomaz
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Unfortunately I don't know either. Hopefully the others in the group can
help.


--
Stoitcho Goutsev (100) [C# MVP]

Tomaz Koritnik said:
Hi

Thanks but I know that IE browser does not support displaying HTML files
from memory. IIS is out of the questione and I still don'w want to save
HTML to temporary file :). That's why I'm trying to find some other HTML
displaying component that can do this because I don't know if there are
any. Do you know?

regards
Tomaz

Stoitcho Goutsev (100) said:
Tomaz Koritnik,

The web browser expects an URL that could be a file or a URL for a
internet resource that is served by some web server. There is no way that
you can pass a memory stream. Of course it depends on the web browser
control. If you use some special control that accepts that then go for
it. If you are using control like IE what you can do is to create a
simple ASP.NET application with a single page. This page can read the
name of the web page, you want to display, as a parameter. The ASP.NET
page then can read the stream and flush its contents to the
HttpRespond.Output stream.

For this solution though you need IIS running on the machine. However,
easiest solution would be to save the stream in a file and point the
borwser to it.

HTH
Stoitcho Goutsev (100) [C# MVP]


Tomaz Koritnik said:
Hi

I have many short HTML files stored in a binary stream storage to
display
descriptions for various items in application. HTML would be display
inside
application using some .NET control or COM control (like Microsoft
WebBrowser). For each description there is one HTML file and along
description text, it contains links to related information. Clicking
related
information would for example open new form in application and display
some
list of items from DB.

When I load HTML data from stream storage, it is stored in memory inside
memory stream. I could display HTML data by first saving memory stream
contents in a temporary file and then instruct browser control to load
from
that file, but I absolutely don't want to use temporary files in this
process. I want to display HTML data directly from the memory stream (or
some other form of memory storage). Is there any control available for
C#
that can display HTML data directly from memory?

regards
Tomaz
 
S

Sami Vaaraniemi

It is possible to load a HTML string into the AxWebBrowser control. In order
to do this, you first need to navigate the control somewhere so that it will
have the HTML DOM in place. You can then replace the body with your HTML
string. In other words:

- navigate the control to url "about:blank"
- handle the DocumentComplete event like so:

AxWebBrowser browser = ...;
MSHTML.IHTMLDocument2 doc = (MSHTML.IHTMLDocument2)browser.Document;
doc.body.innerHTML = "<body><p>Hello World!</p></body>";

I'm not sure if it is possible to access the header this way, though.

Regards,
Sami
 
S

Stefano \WildHeart\ Lanzavecchia

Tomaz Koritnik said:
Hi

Thanks but I know that IE browser does not support displaying HTML files
from memory.

Actually it does. The details are simple for those who played with the
control low-level (we're talking COM interfaces here) but they've always
been slightly beyond my reach. I remember finding the low-level details in
an open-source project called HtmlEditor:
http://www.itwriting.com/htmleditor/index.php
If you check the source code you'll find that it's all there. You might need
to get rid of some of the additional complexity due to the "editor" bits
that you don't need.

The good news are that in the oncoming version 2.0 of the framework (now in
beta) you'll be able to do this natively because all the relevant interfaces
have been wrapped already. I tried and it just works(tm) :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top