473,406 Members | 2,713 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,406 software developers and data experts.

Getting Web App root directory with HTML / JS code?

I wonder how I can refer or get my web app root directory
without using code behind.

Here is my scenario.

I created the folders below

--WebAppRoot
----common
----img (assume a file called myimage.jpg is inside)
----reports
------finance
------admin

I hosted the app @ http://www.myhost.com/WebApps/

If I want to refer to http://www.myhost.com/ root dir, I
can use /WebApps/img/myimage.jpg. I also can use relative
path ../img/myimages.jpg if the HTML file is in reports
folder and ../../img/myimages if I'm in Finance folder.

My problem is I created a ASCX control which to be used
by all the pages. This ASCX control will render an IMG
tag that use this image. How should I specify the src for
this IMG tag? I cannot hard code my image to /WebApps
since WebApps dir may change later.

What is the industrial practice? Use code behind? How
would the code behind looks like if that is the case.


Nov 19 '05 #1
1 6446
You want to set you img tags to runat =server and then tchange the url to
have ~ in front of them. ~ will be replaced by the root url for your
application when compiled.

for example

<img runat="server" id="Img1" src="~/img/myimage.jpg">

this will output src="http://www.myhost.com/WebApps/img/myimage.jpg"

MattC

"Joel Leong" <ch******@hotmail.com> wrote in message
news:16****************************@phx.gbl...
I wonder how I can refer or get my web app root directory
without using code behind.

Here is my scenario.

I created the folders below

--WebAppRoot
----common
----img (assume a file called myimage.jpg is inside)
----reports
------finance
------admin

I hosted the app @ http://www.myhost.com/WebApps/

If I want to refer to http://www.myhost.com/ root dir, I
can use /WebApps/img/myimage.jpg. I also can use relative
path ../img/myimages.jpg if the HTML file is in reports
folder and ../../img/myimages if I'm in Finance folder.

My problem is I created a ASCX control which to be used
by all the pages. This ASCX control will render an IMG
tag that use this image. How should I specify the src for
this IMG tag? I cannot hard code my image to /WebApps
since WebApps dir may change later.

What is the industrial practice? Use code behind? How
would the code behind looks like if that is the case.

Nov 19 '05 #2

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

Similar topics

4
by: Mxsmanic | last post by:
The require() I'm using in a PHP script has stopped working after I moved from PHP4 and Apache 1.3.x to PHP5 and Apache 2.x. Now I get messages like this: Warning:...
5
by: Jonathan | last post by:
I am creating a CD-ROM based website template. Things work fine under Windows but when I try to run the site under Linux the path is messed up. Therefore my JavaScript functions misinterpret the...
6
by: john_williams_800 | last post by:
Hi; I am writing an html page that will live on one server in an ms windows network, but access pictures from a directory on another ms windows server in the network. I know in html the...
2
by: Stephen | last post by:
I need some help with this. I have two files page.aspx: A page that a user calls uc.ascx: A user control that page.aspx uses. The ascx file has HTML used for a site background which would...
5
by: Leszek | last post by:
Hello, Could anybody explain what's a difference between a virtual directory and an application root under IIS? I'm a little bit confused. This is mu problem: Let's assume the following...
1
by: Michał Januszczyk | last post by:
How can I retrieve web application name (or virtual dir name)? (Actually I need physical root directory of web application) I want to open some files in web application root relative...
19
by: Steve Franks | last post by:
I am using VS.NET 2005 beta 2. When I run my project locally using the default ASP.NET Development Web Server it runs using a root address like this: http://localhost:11243/testsite/ However...
4
by: herc | last post by:
My objective is to get the "label" information for the different volumes that are mounted. I want to display the same information as Windows Explorer. I wrote this test code with gets me the...
13
by: lawpoop | last post by:
Hello all - I have a two part question. First of all, I have a website under /home/user/www/. The index.php and all the other website pages are under /home/user/www/. For functions that are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.