Webbrowser, DocumentText and local image

  • Thread starter Thread starter badzio
  • Start date Start date
B

badzio

Hi,

I've new problem with WebBrowser :)
I generate html document at runtime and display it in webbrowser using
code:
WebBrowser webbrowser;
String myHtmlDoc;
webbrowser = new WebBrowser();
myHtmlDoc = @"<html>message to display <img='\temp\image.png' \></
html>";
webbrowser.DocumentText = myHtmlDoc;

the result is:
I see text 'message to display' but instead of image I see 'red X' -
you know, the image which is shown when browser cannot find the image
to display.
Ofcourse path \temp\image.png is valid, this file exists.
If I create a document on the device with mentioned content and load
it to webbrowser (using Navigate()) than image is displayed.
If I use image from network:
myHtmlDoc = @"<html>message to display <img='http://server/image.png'
\></html>";
than the image is displayed.
Seems that in DocumentText cannot contain reference to image on the
device. Does anybody know how to solve that problem?
 
Wouldn't that need to be "file://temp/image.png" or something like that? The
problem is likely to be that the WebBrowser doesn't know what the root path
from which the HTML was loaded is, so it can't interpret \temp\image.png.
That is \ related to where? What server? There might be some way to tell
the WebBrowser object that information before you set up the document text, I
suppose...

Paul T.
 
I guess that, if you've checked everything that could work for the case of
setting the document text explicitly, maybe you should look at other methods
of getting the browser object to load your generated page (generate it to
disk and point the browser to it, etc.)

Paul T.
 
Yeah, I've solved that problem by writing html on the device and load
it from local storage. Hope that client'll accept creating temporary
file :)
But if anybody solve that problem another way, I'd be greatful
 
Another question - does WebBrowser support javascript? If yes, than is
any event called when <img /> element got focus?
I've checked with onfocus and onactivate - doesn't work.
I use smartphone so focus in html page is changed by cursors. I'd like
to change source image when <img /> is selected.

Yeah, I've solved that problem by writing html on the device and load
it from local storage. Hope that client'll accept creating temporary
file :)
But if anybody solve that problem another way, I'd be greatful

I guess that, if you've checked everything that could work for the caseof
setting the document text explicitly, maybe you should look at other methods
of getting the browser object to load your generated page (generate it to
disk and point the browser to it, etc.)
badzio said:
I didn't find any method to tell WebBrowser what's the root. file://
didin't help.
On 13 Sty, 20:02, Paul G. Tobey [eMVP] <paultobey _at_ earthlink _dot_
net> wrote:
Wouldn't that need to be "file://temp/image.png" or something like that?  The
problem is likely to be that the WebBrowser doesn't know what the root path
from which the HTML was loaded is, so it can't interpret \temp\image.png.  
That is \ related to where?  What server?  There might be some way to tell
the WebBrowser object that information before you set up the document text, I
suppose...
Paul T.
:
Hi,
I've new problem with WebBrowser :)
I generate html document at runtime and display it in webbrowser using
code:
WebBrowser webbrowser;
String myHtmlDoc;
webbrowser = new WebBrowser();
myHtmlDoc = @"<html>message to display <img='\temp\image.png'\></
html>";
webbrowser.DocumentText = myHtmlDoc;
the result is:
I see text 'message to display' but instead of image I see 'red X' -
you know, the image which is shown when browser cannot find the image
to display.
Ofcourse path \temp\image.png is valid, this file exists.
If I create a document on the device with mentioned content and load
it to webbrowser (using Navigate()) than image is displayed.
If I use image from network:
myHtmlDoc = @"<html>message to display <img='http://server/image.png'
\></html>";
than the image is displayed.
Seems that in DocumentText cannot contain reference to image on the
device. Does anybody know how to solve that problem?
.
.
 
Some versions do, some not. Without knowing what version you're talking
about, I don't think there's an answer.

Paul T.

Another question - does WebBrowser support javascript? If yes, than is
any event called when <img /> element got focus?
I've checked with onfocus and onactivate - doesn't work.
I use smartphone so focus in html page is changed by cursors. I'd like
to change source image when <img /> is selected.
 
Something strange.. this solution works fine on emulator.
On SPV e650 browser doesn't show page loaded from local storage.
Display is empty. I load:
browser.Navigate(new Uri("\\temp\\page.html"))
path is valid because if I use incorrect filename than webbrowser
shows error 'not found'
If I load page from internet - that's ok.

Yeah, I've solved that problem by writing html on the device and load
it from local storage. Hope that client'll accept creating temporary
file :)
But if anybody solve that problem another way, I'd be greatful

I guess that, if you've checked everything that could work for the caseof
setting the document text explicitly, maybe you should look at other methods
of getting the browser object to load your generated page (generate it to
disk and point the browser to it, etc.)
badzio said:
I didn't find any method to tell WebBrowser what's the root. file://
didin't help.
On 13 Sty, 20:02, Paul G. Tobey [eMVP] <paultobey _at_ earthlink _dot_
net> wrote:
Wouldn't that need to be "file://temp/image.png" or something like that?  The
problem is likely to be that the WebBrowser doesn't know what the root path
from which the HTML was loaded is, so it can't interpret \temp\image.png.  
That is \ related to where?  What server?  There might be some way to tell
the WebBrowser object that information before you set up the document text, I
suppose...
Paul T.
:
Hi,
I've new problem with WebBrowser :)
I generate html document at runtime and display it in webbrowser using
code:
WebBrowser webbrowser;
String myHtmlDoc;
webbrowser = new WebBrowser();
myHtmlDoc = @"<html>message to display <img='\temp\image.png'\></
html>";
webbrowser.DocumentText = myHtmlDoc;
the result is:
I see text 'message to display' but instead of image I see 'red X' -
you know, the image which is shown when browser cannot find the image
to display.
Ofcourse path \temp\image.png is valid, this file exists.
If I create a document on the device with mentioned content and load
it to webbrowser (using Navigate()) than image is displayed.
If I use image from network:
myHtmlDoc = @"<html>message to display <img='http://server/image.png'
\></html>";
than the image is displayed.
Seems that in DocumentText cannot contain reference to image on the
device. Does anybody know how to solve that problem?
.
.
 
How to check the version? It's webbrowser from CF .Net, which I use in
visual studio. Tested on emulator WM6 professional.
 
More details. On SE xperia is launched Opera Mobile to open html from
local storage.
so:
browser.Navigate(new Uri("\\temp\\page.html"))
on spv e650 nothing happens, on xperia Opera Mobile is launched
browser.Navigate(new Uri("http://www.google.pl"))
on e650 and xperia embedded webbrowser, control from application, is
used
Why?

Something strange.. this solution works fine on emulator.
On SPV e650 browser doesn't show page loaded from local storage.
Display is empty. I load:
browser.Navigate(new Uri("\\temp\\page.html"))
path is valid because if I use incorrect filename than webbrowser
shows error 'not found'
If I load page from internet  - that's ok.

Yeah, I've solved that problem by writing html on the device and load
it from local storage. Hope that client'll accept creating temporary
file :)
But if anybody solve that problem another way, I'd be greatful
I guess that, if you've checked everything that could work for the case of
setting the document text explicitly, maybe you should look at other methods
of getting the browser object to load your generated page (generate it to
disk and point the browser to it, etc.)
Paul T.
:
I didn't find any method to tell WebBrowser what's the root. file://
didin't help.
On 13 Sty, 20:02, Paul G. Tobey [eMVP] <paultobey _at_ earthlink _dot_
net> wrote:
Wouldn't that need to be "file://temp/image.png" or something like that?  The
problem is likely to be that the WebBrowser doesn't know what theroot path
from which the HTML was loaded is, so it can't interpret \temp\image.png.  
That is \ related to where?  What server?  There might be some way to tell
the WebBrowser object that information before you set up the document text, I
suppose...
Paul T.
:
Hi,
I've new problem with WebBrowser :)
I generate html document at runtime and display it in webbrowser using
code:
WebBrowser webbrowser;
String myHtmlDoc;
webbrowser = new WebBrowser();
myHtmlDoc = @"<html>message to display <img='\temp\image.png' \></
html>";
webbrowser.DocumentText = myHtmlDoc;
the result is:
I see text 'message to display' but instead of image I see 'redX' -
you know, the image which is shown when browser cannot find theimage
to display.
Ofcourse path \temp\image.png is valid, this file exists.
If I create a document on the device with mentioned content andload
it to webbrowser (using Navigate()) than image is displayed.
If I use image from network:
myHtmlDoc = @"<html>message to display <img='http://server/image.png'
\></html>";
than the image is displayed.
Seems that in DocumentText cannot contain reference to image onthe
device. Does anybody know how to solve that problem?
.
.
 
The browser is permanently linked to the OS version. If you have Windows
Mobile 5, you can never add to that the browser from Windows Mobile 6.1, say.

The WebBrowser control in .NET CF is just a thin wrapper around the actual
WebBrowser control used in Internet Explorer Mobile on the device. It has no
significant functionality of its own. There should be at least some
JavaScript support in the WM6.1 version of the browser. You may be able to
find a list of supported script statements online...

Paul T.
 
The device vendor has chosen Opera Mobile as the browser and implemented the
WebBrowser control interface (see my other message), in terms of Opera, not
Internet Explorer Mobile. As a result, different things happen when you do
operations. As you see, Opera opens, presumably because it runs only as a
separate application, not as an embeddable control. The device vendor may
have provided some way to switch the default browser, which might work for
you, if you can live with changing a global setting on the device...

Paul T.

badzio said:
More details. On SE xperia is launched Opera Mobile to open html from
local storage.
so:
browser.Navigate(new Uri("\\temp\\page.html"))
on spv e650 nothing happens, on xperia Opera Mobile is launched
browser.Navigate(new Uri("http://www.google.pl"))
on e650 and xperia embedded webbrowser, control from application, is
used
Why?

Something strange.. this solution works fine on emulator.
On SPV e650 browser doesn't show page loaded from local storage.
Display is empty. I load:
browser.Navigate(new Uri("\\temp\\page.html"))
path is valid because if I use incorrect filename than webbrowser
shows error 'not found'
If I load page from internet - that's ok.

Yeah, I've solved that problem by writing html on the device and load
it from local storage. Hope that client'll accept creating temporary
file :)
But if anybody solve that problem another way, I'd be greatful
On 14 Sty, 22:33, Paul G. Tobey [eMVP] <paultobey _at_ earthlink _dot_
net> wrote:
I guess that, if you've checked everything that could work for the case of
setting the document text explicitly, maybe you should look at other methods
of getting the browser object to load your generated page (generate it to
disk and point the browser to it, etc.)
:
I didn't find any method to tell WebBrowser what's the root. file://
didin't help.
On 13 Sty, 20:02, Paul G. Tobey [eMVP] <paultobey _at_ earthlink _dot_
net> wrote:
Wouldn't that need to be "file://temp/image.png" or something like that? The
problem is likely to be that the WebBrowser doesn't know what the root path
from which the HTML was loaded is, so it can't interpret \temp\image.png.
That is \ related to where? What server? There might be some way to tell
the WebBrowser object that information before you set up the document text, I
suppose...
I've new problem with WebBrowser :)
I generate html document at runtime and display it in webbrowser using
code:
WebBrowser webbrowser;
String myHtmlDoc;
webbrowser = new WebBrowser();
myHtmlDoc = @"<html>message to display <img='\temp\image.png' \></
html>";
webbrowser.DocumentText = myHtmlDoc;
the result is:
I see text 'message to display' but instead of image I see 'red X' -
you know, the image which is shown when browser cannot find the image
to display.
Ofcourse path \temp\image.png is valid, this file exists.
If I create a document on the device with mentioned content and load
it to webbrowser (using Navigate()) than image is displayed.
If I use image from network:
myHtmlDoc = @"<html>message to display <img='http://server/image.png'
\></html>";
than the image is displayed.
Seems that in DocumentText cannot contain reference to image on the
device. Does anybody know how to solve that problem?
.

.
 
// I was going to use the browser control to display
// a print preview and made this prototype.
// The key is the base href in the header

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace CFWBPrintPreview
{
public partial class PrintPreview : Form
{
const string file = @"img001.jpg";
string filePath;

public PrintPreview()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
filePath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
filePath = Path.GetDirectoryName(filePath);
string Head = "<head><title>Print Preview</title><base href=\"file://localhost"+filePath+"/\" /></head>";
string Body = "<body><b><center>Bold Test of the Printer</center></b><br />" +
"This is just a standard line. <u>Underlined</u><br />" +
"Signature <img src=\"" + file + "\" alt=\"img001.jpg\"></body>";
webBrowser1.DocumentText = Head + Body;

}
}
}



Paul G. Tobey [eMVP] wrote:

The device vendor has chosen Opera Mobile as the browser and implemented
15-Jan-10

The device vendor has chosen Opera Mobile as the browser and implemented th
WebBrowser control interface (see my other message), in terms of Opera, no
Internet Explorer Mobile. As a result, different things happen when you d
operations. As you see, Opera opens, presumably because it runs only as
separate application, not as an embeddable control. The device vendor ma
have provided some way to switch the default browser, which might work fo
you, if you can live with changing a global setting on the device..

Paul T

:

Previous Posts In This Thread:

Webbrowser, DocumentText and local image
Hi

I have new problem with WebBrowser :
I generate html document at runtime and display it in webbrowser usin
code
WebBrowser webbrowser
String myHtmlDoc
webbrowser = new WebBrowser()
myHtmlDoc = @"<html>message to display <img='\temp\image.png' \><
html>"
webbrowser.DocumentText = myHtmlDoc

the result is
I see text 'message to display' but instead of image I see 'red X'
you know, the image which is shown when browser cannot find the imag
to display
Ofcourse path \temp\image.png is valid, this file exists
If I create a document on the device with mentioned content and loa
it to webbrowser (using Navigate()) than image is displayed
If I use image from network
myHtmlDoc = @"<html>message to display <img='http://server/image.png
\></html>"
than the image is displayed
Seems that in DocumentText cannot contain reference to image on th
device. Does anybody know how to solve that problem?

Wouldn't that need to be "file://temp/image.png" or something like that?
Wouldn't that need to be "file://temp/image.png" or something like that? Th
problem is likely to be that the WebBrowser does not know what the root pat
from which the HTML was loaded is, so it cannot interpret \temp\image.png
That is \ related to where? What server? There might be some way to tel
the WebBrowser object that information before you set up the document text,
suppose..

Paul T

:

I guess that, if you have checked everything that could work for the case
I guess that, if you have checked everything that could work for the case o
setting the document text explicitly, maybe you should look at other method
of getting the browser object to load your generated page (generate it t
disk and point the browser to it, etc.

Paul T

:

I did not find any method to tell WebBrowser what is the root.
I did not find any method to tell WebBrowser what is the root. file://
didin't help.

On 13 Sty, 20:02, Paul G. Tobey [eMVP] <paultobey _at_ earthlink _dot_
net> wrote:
=A0The
th
=A0
tell
t, I
g'

Some versions do, some not.
Some versions do, some not. Without knowing what version you are talking
about, I do not think there is an answer.

Paul T.

Another question - does WebBrowser support javascript? If yes, than is
any event called when <img /> element got focus?
I have checked with onfocus and onactivate - does not work.
I use smartphone so focus in html page is changed by cursors. I'd like
to change source image when <img /> is selected.

Yeah, I have solved that problem by writing html on the device and loadit from
Yeah, I have solved that problem by writing html on the device and load
it from local storage. Hope that client'll accept creating temporary
file :)
But if anybody solve that problem another way, I'd be greatful


On 14 Sty, 22:33, Paul G. Tobey [eMVP] <paultobey _at_ earthlink _dot_
net> wrote:
f
ods
at? =A0The
t path
png. =A0
y to tell
text, I
ing
-
ge
d
e.png'

Another question - does WebBrowser support javascript?
Another question - does WebBrowser support javascript? If yes, than is
any event called when <img /> element got focus?
I have checked with onfocus and onactivate - does not work.
I use smartphone so focus in html page is changed by cursors. I'd like
to change source image when <img /> is selected.

of
thods
to
_
that? =A0The
oot path
e.png. =A0
way to tell
nt text, I
using
\></
' -
mage
oad
age.png'
he

Something strange.. this solution works fine on emulator.
Something strange.. this solution works fine on emulator.
On SPV e650 browser does not show page loaded from local storage.
Display is empty. I load:
browser.Navigate(new Uri("\\temp\\page.html"))
path is valid because if I use incorrect filename than webbrowser
shows error 'not found'
If I load page from internet - that is ok.

of
thods
to
_
that? =A0The
oot path
e.png. =A0
way to tell
nt text, I
using
\></
' -
mage
oad
age.png'
he

How to check the version?
How to check the version? it is webbrowser from CF .Net, which I use in
visual studio. Tested on emulator WM6 professional.

On 15 Sty, 05:02, "Paul G. Tobey [eMVP]" <paul tobey _AT_ earthlink
_DOT_ net> wrote:
g

More details.
More details. On SE xperia is launched Opera Mobile to open html from
local storage.
so:
browser.Navigate(new Uri("\\temp\\page.html"))
on spv e650 nothing happens, on xperia Opera Mobile is launched
browser.Navigate(new Uri("http://www.google.pl"))
on e650 and xperia embedded webbrowser, control from application, is
used
Why?

se of
methods
t to
/
ot_
e that? =A0The
root path
age.png. =A0
e way to tell
ment text, I
r using
g' \></
X' -
image
load
image.png'
the

The browser is permanently linked to the OS version.
The browser is permanently linked to the OS version. If you have Windows
Mobile 5, you can never add to that the browser from Windows Mobile 6.1, say.

The WebBrowser control in .NET CF is just a thin wrapper around the actual
WebBrowser control used in Internet Explorer Mobile on the device. It has no
significant functionality of its own. There should be at least some
JavaScript support in the WM6.1 version of the browser. You may be able to
find a list of supported script statements online...

Paul T.

:

The device vendor has chosen Opera Mobile as the browser and implemented
The device vendor has chosen Opera Mobile as the browser and implemented the
WebBrowser control interface (see my other message), in terms of Opera, not
Internet Explorer Mobile. As a result, different things happen when you do
operations. As you see, Opera opens, presumably because it runs only as a
separate application, not as an embeddable control. The device vendor may
have provided some way to switch the default browser, which might work for
you, if you can live with changing a global setting on the device...

Paul T.

:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Server Side Processing in ADO.NET/WCF Data Services
http://www.eggheadcafe.com/tutorial...f-4f6f92a76585/server-side-processing-in.aspx
 
string Body = "<body><b><center>Bold Test of the Printer</center></b><br />" +
"This is just a standard line. <u>Underlined</u><br />" +
"Signature <img src=\"" + file + "\" alt=\"img001.jpg\"></body>";
webBrowser1.DocumentText = Head + Body;

// if it still gets cutoff it looks like this
// img src="your image.jpg" />
// it uses the base href setup in the header to
// find the image



Ed Tischofer wrote:

This works to display images and just setting document text
27-Apr-10

// I was going to use the browser control to display
// a print preview and made this prototype.
// The key is the base href in the header

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace CFWBPrintPreview
{
public partial class PrintPreview : Form
{
const string file = @"img001.jpg";
string filePath;

public PrintPreview()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
filePath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
filePath = Path.GetDirectoryName(filePath);
string Head = "<head><title>Print Preview</title><base href=\"file://localhost"+filePath+"/\" /></head>";
string Body = "<body><b><center>Bold Test of the Printer</center></b><br />" +
"This is just a standard line. <u>Underlined</u><br />" +
"Signature <img src=\"" + file + "\" alt=\"img001.jpg\"></body>";
webBrowser1.DocumentText = Head + Body;

}
}
}

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Crypto Obfuscator for .NET - Product Review
http://www.eggheadcafe.com/tutorial...f8-f5fd987fafb1/crypto-obfuscator-for-ne.aspx
 
Back
Top