Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 18th, 2004, 12:08 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default iis cannot find images in relative path

I have image in inetpub\wwwroot\treeview\images\tree.gif. When I keyin <IMG height="28" src="..\images\tree.gif" width="34"> It does not find the image. But when I move it up to the same dir as treeview and say <IMG height="28" src="tree.gif" width="34">, it works.

I don't know why it cannot find the image in relative path. Can some help?

 
Old November 18th, 2004, 01:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

It depends on where the file is located. If the file is in the images folder that's why the second one works. Where is the file located?

 
Old November 18th, 2004, 04:53 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

file is located in images folder, I tried src="../images/tree.gif" does not work.

 
Old November 24th, 2004, 12:18 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Try this:

<img src="http://" & Request.ServerVariables("SERVER_NAME") & Request.ApplicationPath & "/images/tree.gif">

Cheers..
Spacy...

 
Old November 30th, 2004, 11:00 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In .NET server controls, any time you wish to reference a server resource (image, user control, another page) you can make use of the "~" character to act as the "home" placeholder. This will always reference the root of the current .NET web application. So if you have an images folder in the root of your web application (regardless of what the web application is named) you can always reference an image like this:

<asp:image imageurl="~/images/someimage.gif" />

No matter where this code falls on a page in any folder under the web application, you'll always end up with an image tag that looks like this:

<img src="/myWebApplication/images/someimage.gif">

Even if you put all the pages/images/code in a whole new application, the reference will be retained:

<img src="/myWholeNewAndDifferentWebApplication/images/someimage.gif">

You can use the same technique for creating links to other pages:

<asp:hyperlink navigateurl="~/somefolder/somepage.aspx">click me</asp:hyperlink>

    results in:

<a href="/myWebApplication/somefolder/somepage.aspx">click me</a>

...or when registering user controls:

<%@ Register TagPrefix="uc" TagName="MyUserControl" Src="~/userControls/MyUserControl.ascx" %>

Also, the functionality that performs this home directory resolution is found on the Page class so you can access and utilize it anywhere in page code-behind:

ResolveUrl("~/someFolder/somePage.aspx")





Similar Threads
Thread Thread Starter Forum Replies Last Post
Relative and Absolute Path question Johnger Pro Visual Basic 2005 1 September 8th, 2006 10:45 AM
Relative Path Connection String fangai Classic ASP Databases 1 October 3rd, 2003 02:37 AM
LDAP and Relative Path problem Dmitriy Pro VB 6 0 July 21st, 2003 12:45 PM
DeleteFile(filespec) with relative path? brandon1974 Classic ASP Basics 1 July 19th, 2003 04:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.