473,545 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6454
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******@hotma il.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
2791
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: main(/includes/ReloadScript.html) : failed to open stream: No such file or directory in /usr/local/www/htdocs/main/AOLCompression.php on line 14 Fatal error: main() : Failed...
5
2210
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 root to be the root of the filesystem instead of the root of the cd. Any cd I make will need to run on Windows and Linux systems and the...
6
13958
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 values for img src use unix style path separators with root ( "/" being your parent web directory. However in windows land the path to my images would...
2
2469
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 display one of two images. If page.aspx is in the root directory, the displayed image has no text. If page.aspx is anywhere but the root directory,...
5
3660
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 directory structure: FileManager (application name a.k.a. virtual directory?)
1
2068
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 directory. Previously I used to open the files when client connected and thus could use the following code to retreive physical file location: string...
19
10178
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 when I deploy to a remote test server running real IIS, the real root of my application becomes: http://localhost/ What I want to do is have it so...
4
4758
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 drive letter, but the label is always blank. Any thoughts? DriveInfo drives = DriveInfo.GetDrives(); foreach (DriveInfo di in drives) {...
13
2786
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 used in multiple files, I have php files under / home/user/www/functions/. These files simply have So, in index.php and other files, I have
0
7486
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...
0
7416
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...
0
7932
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...
1
7442
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...
0
7776
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5347
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3473
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...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
729
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...

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.