adress of project folder

J

Jarod_24

I got a function that return the url of a image, the problem is that the image control on the .aspx page automaticaly adds the
adress of itself to the adress

Example:
The page http://localhost/myapp/pages/misc/index.aspx calls the function, and it returns the string "images\thumb\001.jpg"

The image control on the page will then point to the adress: http://localhost/myapp/pages/misc/images\thumb\001.jpg (wich is wrong).

The image folder is located at root of my project (myapp) so the adress should be: http://localhost/myapp/images\thumbs\001.jpg

Since the pages could be in different sub-folders at different levels under the myapp folder i can't simply add "..\..\..\" to fix
it.

Is there any function that will return the http://localhost/myapp (the rootof my project folder)?
I tried using System.AppDomain.CurrentDomain.BaseDirectory() but that will return the path as "c:\inetwww\myapp\"
 
B

Bruno Sirianni

You can use Request.Url, or set an app value in Web.Config.
Brun


Jarod_24 said:
I got a function that return the url of a image, the problem is that the
image control on the .aspx page automaticaly adds the
adress of itself to the adress

Example:
The page http://localhost/myapp/pages/misc/index.aspx calls the function,
and it returns the string "images\thumb\001.jpg"
The image control on the page will then point to the adress:
http://localhost/myapp/pages/misc/images\thumb\001.jpg (wich is wrong).
The image folder is located at root of my project (myapp) so the adress
should be: http://localhost/myapp/images\thumbs\001.jpg
Since the pages could be in different sub-folders at different levels
under the myapp folder i can't simply add "..\..\..\" to fix
it.

Is there any function that will return the http://localhost/myapp (the rootof my project folder)?
I tried using System.AppDomain.CurrentDomain.BaseDirectory() but that will
return the path as "c:\inetwww\myapp\"
 
K

Ken Cox [Microsoft MVP]

Don't forget that the tilde (~) is resolved as the root of the Web. That
means you can get at the images folder from anywhere using syntax like this:

Image1.ImageUrl = "~/images/thumbs/001.jpg"

Ken
Microsoft MVP [ASP.NET]
 
J

Jarod_24

Ken Cox said:
Don't forget that the tilde (~) is resolved as the root of the Web. That
means you can get at the images folder from anywhere using syntax like this:

Image1.ImageUrl = "~/images/thumbs/001.jpg"

Ken
Microsoft MVP [ASP.NET]

Thanks. That worked like a charm.
Just added a "~/" at the start of the string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top