Link to home
Start Free TrialLog in
Avatar of Rabbit W
Rabbit W

asked on

Hyperlink based on the file system

I have images saved in different Idproduct folder. Each image will be linked to a third-party website with the same image. I followed  the expert Snarf0001's  example. But has error saying 'i' is not declared. It may be inaccessible due to its protection level.
Below is the coding:
 <a href="http://www.xxx.com/sku=<%=productsku%>&imagelocation=images/600x600/<%=idProduct%>/<%= System.IO.Path.GetFileName(imageList(i)) %>"><img width="60px" height="60px" src="images/600x600/<%=idProduct%>/<%= System.IO.Path.GetFileName(imageList(i)) %></a> 

Open in new window


Please advise! Thank you!
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

need a link to the original question
Your problem is here: imageList(i)

The compiler does not 'know' what the letter i in the brackets is.  Somewhere else you probably have assigned a value to a variable called i but where this line of code is that variable is not accessible.  (This is very basic coding - scope and lifetime of variables)

eg.
{
  int i = 42;
  //more code
}//i is now destroyed
imageList(i) = xxxx;   //fails because i does not exist here
The approach you're using above likely won't work.

You're doing the equivalent of file://path-to-file which will only work if /path-to-file exists on the local user's machine.

So if you have public website, serving out file:// links no visitor will be able to access this file, until they download it first.

Maybe this is the behavior you're targeting. If it is, then you must ensure all visitors first download all file:// referenced files.

So... to be clear... your code above looks like it produces a filename local to the server, not local to the browser.
Hi again Rabbit, again I'm going to hound you to put in more information.  Without the details of the page and what's going on, we're just guessing.

@David J - this is the original question:
https://www.experts-exchange.com/questions/29128857/Images.html

@David F - it's actually just retrieving the end filename, not the entire path, of the selected folder that's being read from.

Some context for you guys - loading images in a jquery carousel.  The images are NOT stored in a database or anywhere else, stored solely in the filesystem under the "/images" path, with multiple directories based on product.
images/600x600/productid/xxxxx
images/300x300/productid/xxxxx

Each product has a different number of images.  So solution (without introducing a database) was to ready on page_load (not shown in the code above) the images in the target productid folder, save in an array, and use that when populating the actual lists (two of them).

imageList above is the array that holds the names, which is used in a for loop in previous examples.

@Rabbit - more details pls :)
Avatar of Rabbit W
Rabbit W

ASKER

Thank you again Snarf0001! Thank you David!

Like what Snarf001 said, all the images are stored in the file system.
Here is the link for the site as an example
You will see ADD YOUR LOGO button. When the button is clicked and it is linked to the next page, where the image presented is exactly the same one which  the users  mouse over.

I am sorry about the confusion and hopefully I make it clear this time.  Thank you!
Where things are and what they are are pretty much irrelevant to the error reported.  Please read my earlier comment.
Thanks Rabbit, the link helps a lot to understand what your actually doing.
But now where are you trying to put the <a> tag in above?  From the link you showed, everything is working.  You click on the 3rd image of the glass it replaces the big one.  And anytime i click the button, it takes me to a different site with that specific image.

So what are you trying to change on here?  Where are you trying to use the image links?
No I am not changing anything. I just want to add the extra button on the current page. Something like the page on the link.
If I want to do something like this, the third party provides the link which will link ours to theirs like:
http://www.technologo.com/vSampleLite?sku=<%=productsku%>&imagelocation=xxx(that is the image I need to load and that is something I need to do)
BTW, the link https://www.tervispromo.com/p/product/206179bc-288f-48ec-bb90-874b696c628f/9oz-tervis-wine-glass-stemless
I provided is the example of what I want to accomplish.  Sorry about the confusion and thank you!
I am waiting for your experts' advice.
>>I am waiting for your experts' advice.
From your question.
>>But has error saying 'i' is not declared.

Your original error message has been explained along with more information about local and remote file systems.

I would suggest you close your original question and ask a new question about what you have decided you really want.
Thank you for all the experts' advice! I have worked it out.
I have given up CLICK BUTTON.  What I mean "Solved  it of my own" is that I have used different ways, which is irrelevant to the topic.
Thanks for all the experts who have given me the valuable advice. Thank you Snarf0001!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.