473,625 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7540
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.co m

<ti***********@ gmail.comwrote in message
news:11******** **************@ o5g2000hsb.goog legroups.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.co m

"Zytan" <zy**********@g mail.comwrote in message
news:11******** *************@b 75g2000hsg.goog legroups.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.c ss" 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.Douc ment.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:blan k". 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.co m

"Zytan" <zy**********@g mail.comwrote in message
news:11******** *************@n 59g2000hsh.goog legroups.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.c ss" 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.Douc ment.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:blan k". You can't resolve relative URLs that way.
Right, that matches what I think. Since I do navigate to
"about:blan k" to get WebBrowser.Docu ment 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
3801
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
3456
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, displays, and executes. To gain this control, you need to implement your host's IDispatch so it handles DISPID_AMBIENT_DLCONTROL. When the WebBrowser Control is instantiated, it will call your IDispatch::Invoke with this ID. Set pvarResult to a...
12
6355
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 of course it's thrown up a whole host of new issues... I'm generating a multi page printable document in HTML from my app, and displaying it in a WebBrowser control. I've looked into using some CSS
8
3398
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
8688
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 regular File IO it knows to go to current directory but not WebBrowser. What do I need to change? Is there some System property which stores the path the application is running from that I can use? string resource = "somefile.htm";...
11
2816
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
1175
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 changes made to the document.
4
11997
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 the WebBrowser control is sending. Effectively, my code would be the web server and the WebBrowser control would be the web client. All the examples I am seeing have the WebBrowser control being directed to a URL from which to get the HTML...
5
8058
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 this status bar. How can i do this? Thanks.
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.