473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

current directory of WebBrowser control

The WebBrowser control won't load a css file written in the same
directory as the program. If I put an absolute path to it, it will
load it. Thus, the current directory of the WebBrowser control isn't
the current directory of the program. What is the current directory?
I don't want to use an absolute path, since its contents are saved to
disk, and that should always load the css file no matter where it and
the css file exists.

Titan

Mar 27 '07 #1
6 7501
Titan,

That's not true. You must be specifying something in the style element
incorrectly. The web browser has no concept of a current directory when it
is run. The program might, but it doesn't impact anything that the web
browser does. All relative URLs are resolved in relation to the address of
the document that was loaded.

Can you show the HTML and the CSS page? Something tells me that you
might have specified the CSS file incorrectly in the style tag, or you are
missing something from the style tag.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ti***********@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
The WebBrowser control won't load a css file written in the same
directory as the program. If I put an absolute path to it, it will
load it. Thus, the current directory of the WebBrowser control isn't
the current directory of the program. What is the current directory?
I don't want to use an absolute path, since its contents are saved to
disk, and that should always load the css file no matter where it and
the css file exists.

Titan

Mar 27 '07 #2
Nicholas,

I see the same behaviour. If the css is referenced with an absolute
path, WebBrowser sees it and uses it. If the css is referenced
without a path, WebBrowser doesn't find it. The syntax of the css is
perfect, AFAIK. It's been tested inside WebBrowser and in an external
browser, and it works in both cases (as long as a path is given to
it). So, the css syntax isn't causing the problem.

The problem must be, as you stated, "The web browser has no concept of
a current directory when it is run". So, where does it look when you
ask for a file without a path? There's really no current directory?
There's gotta be something. That's just weird. Is there any way to
inquire what the directory might be?

You said: "All relative URLs are resolved in relation to the address
of the document that was loaded." I've noticed that when I navigate
away from a webpage I made in memory, I cannot return to it (although
I can return to any 'real' webpages I click to, as long as I allow
navigation), so this original webpage of mine doesn't 'really exist'.
So, if it doesn't, then relative paths have nothing to go by. But
again, what does it do? Just assume the file doesn't exist? Seems
strange to me. But, I guess we can't change that.
Can you show the HTML and the CSS page?
CSS:

body
{
color: black;
font-family: georgia;
}

HTML:

<link rel="stylesheet" type="text/css" href="log.css" />
html code here

The only solutions I see:

1. include absolute path to CSS (but then the HTML file written to
disk will not work if the CSS is ever moved).

2. include the CSS inside the HTML itself (but then you cannot change
one CSS file and have all HTML files reformatted).

(I am creating an HTML + CSS, for a logger, and showing it in a
WebBrowser in real-time, but also saving them to disk for later
access)

Zytan

Mar 27 '07 #3
Zytan,

Files can't not have paths. If you have a relative URL in an HTML page,
and you loaded it from disk, then the web browser will look relative to the
URL that the page was loaded from, i.e. the location on disk. Because of
that, you have to place the CSS file in the same directory (that is how the
relative URL will be resolved).

The only case where this won't work is if you loaded the page from
memory. If you loaded the page from memory. The only way you can do this
with the WebBrowser control is to set the DocumentStream property, or to use
the IPersistMemory COM interface on MSHTML (the Document class).

Is this how you are loading it? Or are you using a file url?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11*********************@b75g2000hsg.googlegro ups.com...
Nicholas,

I see the same behaviour. If the css is referenced with an absolute
path, WebBrowser sees it and uses it. If the css is referenced
without a path, WebBrowser doesn't find it. The syntax of the css is
perfect, AFAIK. It's been tested inside WebBrowser and in an external
browser, and it works in both cases (as long as a path is given to
it). So, the css syntax isn't causing the problem.

The problem must be, as you stated, "The web browser has no concept of
a current directory when it is run". So, where does it look when you
ask for a file without a path? There's really no current directory?
There's gotta be something. That's just weird. Is there any way to
inquire what the directory might be?

You said: "All relative URLs are resolved in relation to the address
of the document that was loaded." I've noticed that when I navigate
away from a webpage I made in memory, I cannot return to it (although
I can return to any 'real' webpages I click to, as long as I allow
navigation), so this original webpage of mine doesn't 'really exist'.
So, if it doesn't, then relative paths have nothing to go by. But
again, what does it do? Just assume the file doesn't exist? Seems
strange to me. But, I guess we can't change that.
> Can you show the HTML and the CSS page?

CSS:

body
{
color: black;
font-family: georgia;
}

HTML:

<link rel="stylesheet" type="text/css" href="log.css" />
html code here

The only solutions I see:

1. include absolute path to CSS (but then the HTML file written to
disk will not work if the CSS is ever moved).

2. include the CSS inside the HTML itself (but then you cannot change
one CSS file and have all HTML files reformatted).

(I am creating an HTML + CSS, for a logger, and showing it in a
WebBrowser in real-time, but also saving them to disk for later
access)

Zytan

Mar 27 '07 #4
Files can't not have paths.

Huh? Please elaborate.
If you have a relative URL in an HTML page,
and you loaded it from disk, then the web browser will look relative to the
URL that the page was loaded from, i.e. the location on disk. Because of
that, you have to place the CSS file in the same directory (that is how the
relative URL will be resolved).
Yes, I understand all of this. I presume for the webpage loaded from
memory that there is nothing for the relative path to 'connect' to?
I.e. where is ".\format.css" when the webpage is in memory?
The only case where this won't work is if you loaded the page from
memory. If you loaded the page from memory. The only way you can do this
with the WebBrowser control is to set the DocumentStream property, or to use
the IPersistMemory COM interface on MSHTML (the Document class).
Is this how you are loading it? Or are you using a file url?
I use WebBrowser.Doucment.Write(). The webpage does not exist as a
file. The CSS file does. I assumed that the webpage in memory
'existed' at least in the current directory of the HD. But, I guess
it does not.

I thought of a 3rd solution:

3. Write out the webpage to a file, then load that file into
WebBrowser, then it'll have a current directory. (But then, you need
to save a new file as my logger appends to it, and reload the file,
each time. This is slow.)

I think the best solution is to provide the CSS internally in the HTML
file itself. I'd prefer to 'force' a current HD directory so that the
CSS is separate, but if I cannot do that, then inlining it is best.

Zytan

Mar 27 '07 #5
Zytan,

I used a double-negative. I was stating that if you were indeed loading
the file from disk, then you would have a URL to figure out relative urls
against. However, since you are using Document.Write, my assumption is that
the base url is "about:blank". You can't resolve relative URLs that way.

I would recommend writing the HTML to a disk file, and then writing the
CSS file in the same directory. This way, you can keep the two separate,
and the HTML will render correctly.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11*********************@n59g2000hsh.googlegro ups.com...
> Files can't not have paths.

Huh? Please elaborate.
> If you have a relative URL in an HTML page,
and you loaded it from disk, then the web browser will look relative to
the
URL that the page was loaded from, i.e. the location on disk. Because of
that, you have to place the CSS file in the same directory (that is how
the
relative URL will be resolved).

Yes, I understand all of this. I presume for the webpage loaded from
memory that there is nothing for the relative path to 'connect' to?
I.e. where is ".\format.css" when the webpage is in memory?
> The only case where this won't work is if you loaded the page from
memory. If you loaded the page from memory. The only way you can do
this
with the WebBrowser control is to set the DocumentStream property, or to
use
the IPersistMemory COM interface on MSHTML (the Document class).
Is this how you are loading it? Or are you using a file url?

I use WebBrowser.Doucment.Write(). The webpage does not exist as a
file. The CSS file does. I assumed that the webpage in memory
'existed' at least in the current directory of the HD. But, I guess
it does not.

I thought of a 3rd solution:

3. Write out the webpage to a file, then load that file into
WebBrowser, then it'll have a current directory. (But then, you need
to save a new file as my logger appends to it, and reload the file,
each time. This is slow.)

I think the best solution is to provide the CSS internally in the HTML
file itself. I'd prefer to 'force' a current HD directory so that the
CSS is separate, but if I cannot do that, then inlining it is best.

Zytan

Mar 27 '07 #6
I used a double-negative. I was stating that if you were indeed loading
the file from disk, then you would have a URL to figure out relative urls
against. However, since you are using Document.Write, my assumption is that
the base url is "about:blank". You can't resolve relative URLs that way.
Right, that matches what I think. Since I do navigate to
"about:blank" to get WebBrowser.Document to not be null. So, any
Write from there is appending to that. If I navigated to a blank HTML
in the current directory, then that would probably also work, since
we'd then have a real current directory.
I would recommend writing the HTML to a disk file, and then writing the
CSS file in the same directory. This way, you can keep the two separate,
and the HTML will render correctly.
The reason I choose against this, which I've already stated, is that
(in my case) the log file is to be displayed in real time. Thus, I
have to write to the file, and reload the entire file, for the
WebBrowser to show properly. Simply doing Write is much faster, since
it just appends, which is exactly what a logger wants. So, my
solution is to write the CSS internally in the HTML. Unfortunately,
this combines form and content, but it's not so bar for just a log
file.

Zytan

Mar 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: ASP .NET Newbie | last post by:
How can I run a WebBrowser control using ASP.NET/VB.NET? I know I can use the WebClient to get the page data, but I need to be able to use the WebBrowser (AxWebBrowser)? Thanks, Chad
0
by: Jim Hubbard | last post by:
How would I implement the IDispatch interface to handle the following in VB.Net <BEGIN> Controlling Download and Execution The WebBrowser Control gives you control over what it downloads,...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
8
by: Prosperz | last post by:
Hi, I would like to make thumbnails of web page by capture content of a WebBrowser. By example, capture http://www.google.com. I used WebBrowser control with Framework 2.0. I try this : ...
1
by: MrNobody | last post by:
I want to load a document which would be residing in the same directory as the application so I pass in a string to WebBrowser control which has no path information- normally doing this with...
11
by: Anil Gupte | last post by:
....and how do I insert one into my form? I used in VB 6.0 last, but cannot figure out where it is in .Net Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
0
by: Dean Richardson | last post by:
Hello, I am currently building a windows application in VB.NET. At the moment I have a word document saved locally which I open with the WebBrowser control. I cannot seem to save the...
4
by: Steve Richter | last post by:
I would like to build an HTML stream as a string and have the WebBrowser control render that HTML. Then on PostBack, or whatever it is called, I would like my code to be the one that receives what...
5
by: kimiraikkonen | last post by:
Hi, I couldn't find a necessary class which shows when mouse hovers on a link in Webbrowser control. Think of there's a status bar(text), when mouse comes on a link, the URL must be shown in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.