Making absolute path using Application variables??

Results 1 to 3 of 3

Thread: Making absolute path using Application variables??

  1. #1
    Join Date
    Dec 1969

    Default Making absolute path using Application variables??

    I am working on a site and facing a problem in giving relative paths. I am not able to access the images properly from various folders. I am using usercontrols for header, footer etc. In these control, the path of the images are specified as relative ie like ../images/go.gif. I don&#039;t want to give absoulte path as later on main folder name can change and then I will have to change the paths in my whole code and I also want to use common files wherever possible.<BR><BR>In ASP, I used to create Application varibale for the main directory name in global.asa and used to concatenate this variable with image path. So it used to work always as I was giving absolute path always. In, I was able to create global variuable but I am not able to use it within the code. I am using it like:<BR><BR>&#060;img height="57" src="&#060;%=Application(&#039;strPath&#039;)%&#06 2;/Images/h-quicktour.gif" width="200" /&#062; Is it the right way for using it or I am making some mistake in this.<BR><BR>I am getting this error:<BR><BR>BC30201: Expression expected.<BR><BR>Please help!!

  2. #2
    Join Date
    Dec 1969

    Default use root addressing instead of relative addressing

    &nbsp;<BR> &#060;img src="/images/myimage.gif" &#062;<BR><BR> The slash before the "images" folder forces the path<BR> search to start at the root folder of the website regardless<BR> of where the current .aspx page lives in the folder hierarchy.<BR><BR> You can use this for all client side files and paths. However,<BR> if you use cookieless sessions, you can&#039;t use root addressing<BR> for form page paths or response.redirect paths.<BR><BR> But, it works great for images, javascript files, etc...

  3. #3
    Join Date
    Dec 1969

    Default RE: Making absolute path using Application variabl

    There are a couple of things:<BR>First, in .NET I have found that the server doesn&#039;t like single quotes, especially if you&#039;re using VB. So the correct Syntax for what you&#039;re trying above would be <BR>&#060;img src=&#039;&#060;%=Application("strPath")%&#062;/images/quicktour.gif&#039; width="200"&#062;<BR>You see where I use the single quotes for the HTML part and double quotes for the ASP?<BR><BR>The second thing is that with any server control, to get access to the root of the application, you precede the starting / with a tilde (~). Based on my limited testing, it doesn&#039;t seem to work for html controls. So a better way to access your images would be to use.....<BR>&#060;img src="~/images/quicktour.gif" width="200" runat="server" /&#062;<BR><BR>By including the runat="server" attribute, you&#039;ve just converted your image to a server control. This way, no matter how deep down your application gets, or what the name of the folder is, the aspx page will know to start the search for the image from the root of the application.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts