View HTML Email in WPF Webbrowser

748 views Asked by At

In my application I send HTML Email receipts to customers after finishing an order. What I would like to do is preview this in a webbrowser control.

The code I have works fine, but the images are missing in the browser.

I create the HTML in an AlternateView like this:

Dim hview As AlternateView = AlternateView.CreateAlternateViewFromString(ReadTemplate(order), Nothing, "text/html")

Then loop through the images they ordered and add them like this:

Dim M As New LinkedResource(ResizeAndRotate(I.Path), Net.Mime.MediaTypeNames.Image.Jpeg) With {.ContentId = "Main" & cnt}
hview.LinkedResources.Add(M)

Then return a document from the hview stream:

Dim ObjDoc As New HTMLDocument
Dim Doc As IHTMLDocument2 = ObjDoc
Dim reader As New IO.StreamReader(hview.ContentStream)
Doc.write(reader.ReadToEnd)
Return ObjDoc

How would I also get the images from the stream?

2

There are 2 answers

1
Sheridan On BEST ANSWER

I don't believe that you can use images from memory. You'll need to save them to the hard drive, even temporarily. The you have to reference them in your HTML something like this:

<img alt="An image" src="file:///C:/Images/Image.jpg" width="400" height="400" />
0
noseratio On

You can encode your image data with base64 and embed it inline on the page, as supported with Data URI scheme. Example:

<!-- http://en.wikipedia.org/wiki/Data_URI_scheme -->
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg=="/>

Of course, that would add some overhead to the page size, which may by substantial, depending on the original image size.