473,372 Members | 1,374 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,372 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 7506
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...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.