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

how to specify relate path from application root

Hi all,

I think this question should be fairly common but I couldn't find any
existing answers in the forums.

I have a Master Page that refers to uses some client scripts like so:

<script language="javascript" type="text/javascript" src="Scripts/
Browser.js" />
<script language="javascript" type="text/javascript" src="Scripts/
Common.js" />

So any pages that inherit from this master page will automatically use
these scripts. And it works fine for pages in the application's root
directory BUT but all the pages I have under an \Admin\ directory
don't work as it tries to find the scripts under /WebsiteRoot/Admin/
Scripts/ instead of /WebsiteRoot/Scripts/

It seems I can't use "~" either! e.g. src="~/Scripts/Browser.js"

I reckon this would have to be a common problem encountered by asp.net
developers! So I'm desperate to find out how others (and how I can)
get around this problem.

Thanks in advance, Ben

Oct 13 '07 #1
4 5020
Hello Ben,

why not to specify the full path to your files from the root directory?
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
BDHi all,
BD>
BDI think this question should be fairly common but I couldn't find
BDany existing answers in the forums.
BD>
BDI have a Master Page that refers to uses some client scripts like
BDso:
BD>
BD<script language="javascript" type="text/javascript" src="Scripts/
BDBrowser.js" />
BD<script language="javascript" type="text/javascript" src="Scripts/
BDCommon.js" />
BDSo any pages that inherit from this master page will automatically
BDuse these scripts. And it works fine for pages in the application's
BDroot directory BUT but all the pages I have under an \Admin\
BDdirectory don't work as it tries to find the scripts under
BD/WebsiteRoot/Admin/ Scripts/ instead of /WebsiteRoot/Scripts/
BD>
BDIt seems I can't use "~" either! e.g. src="~/Scripts/Browser.js"
BD>
BDI reckon this would have to be a common problem encountered by
BDasp.net developers! So I'm desperate to find out how others (and how
BDI can) get around this problem.
BD>
BDThanks in advance, Ben
BD>
Oct 13 '07 #2
Hi Ben,

Ben Daniel schrieb:
I have a Master Page that refers to uses some client scripts like so:

<script language="javascript" type="text/javascript" src="Scripts/
Browser.js" />
these scripts. And it works fine for pages in the application's root
directory BUT but all the pages I have under an \Admin\ directory
don't work as it tries to find the scripts under /WebsiteRoot/Admin/
Scripts/ instead of /WebsiteRoot/Scripts/

It seems I can't use "~" either! e.g. src="~/Scripts/Browser.js"
That's right, "~" is an ASP.NET expression and only works in ASP.NET
controls.

I faced this problem recently, and I simply added an ASP.NET Literal
control instead of the HTML tag and set the text of the literal to the
complete HTML tag in code behind. Depending on the request, it adds
"../" in front of the path.
This was for an embed-Tag to embed a flash file, but I would think it
also works for a JS reference.

Hope this helps,

Roland
Oct 13 '07 #3
"Roland Dick" <br*****@web.dewrote in message
news:eP**************@TK2MSFTNGP03.phx.gbl...
This was for an embed-Tag to embed a flash file, but I would think it also
works for a JS reference.
It does.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 13 '07 #4
Thanks for your help everyone.

What I ended up doing was looking at the code behind the asp:image
control to see how it resolves the url in the ImageUrl property. It
calls a ResolveClientUrl function defined in Control. So I ended up
just doing this:

<script language="javascript" type="text/javascript" src="<%=
ResolveClientUrl("Scripts/Browser.js") %>" />
<script language="javascript" type="text/javascript" src="<%=
ResolveClientUrl("Scripts/Common.js") %>" />

Which works a treat. Thanks anyway.

Oct 14 '07 #5

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

Similar topics

5
by: Jordan S | last post by:
I'm kind of new to all of this Web app development and have developed an ASP.NET Web application under the default c:\inetpub\wwwroot\myApp. I just went to move it to a hosted site and I'm having...
2
by: Shimon Sim | last post by:
I have web project that includes few sits that must share some pictures. The project has following structure Root - just a folder with solution files - this is on IIS regular folder Site 1 - web...
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...
6
by: Water Cooler v2 | last post by:
How does one get the root of the ASP.NET application. For instance, my application is: http://localhost/MyApplication/login.aspx Today, it is on a test server, but when I move it to the...
2
by: Anders Bornholm | last post by:
I have the following setup: A website that is completely accessible to a logged-in user. Access control is handled by a third-party external module implemented as an ISAPI filter. The...
6
by: Amjad | last post by:
Can anyone tell me how to read the path value of an already installed and registered application called "Palm Desktop" from the Windows Registry? I just want my VB program to determine where...
4
by: Tee | last post by:
Hi, Can anyone tell me how to get the path of IIS root folder from coding? Eg: C:\Inetpub\wwwroot. I would like to detect it via coding as not everyone set it at the default folder. ...
4
by: John Smith | last post by:
Hello, I'm not sure if these are the appropriate forums for my question since it is closer to about Visual Studio 2005 than it is about .NET framework. So please pardon me and direct me to a...
3
by: Stephen Falken | last post by:
I need to validate incoming XML files in a VB.Net 2005 application that must adhere to a DTD. This DTD is the only schema these XML files need to validate against. How can I specify/load the...
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...
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
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...
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
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...
0
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...

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.