Click here to Skip to main content
15,886,673 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I have html button tag in which I have nested the image tag to show in my application.

The problem is when I use relative path the image tag does not work at all but if I use absolute path it works just fine.

But I do not want to use absolute path because I need to change it if I put this on test server and on main server.

Here is code with absolute path:
C#
treeNode.Append(@"<button ><img src=""http://localhost:62473/mainFolder/Images/image1.png"" width=""30"" height=""15"" alt=""Get Info""></button>");


Here is code with relative path:


C#
treeNode.Append(@"<button ><img src=""~/Images/image1.png"" width=""30"" height=""15"" alt=""Get Info""></button>");



Please help me and let me know where I am going wrong?
Posted

1 solution

Of course it always works. You did no try use relative path anywhere, so I don't know where you screwed it up. The path should be relative the the HTML file using the path. Perhaps you don't quite know the path syntax: '.' is "this directory", '..' means one level up, '~' means root directory set up for your site, and so on.

—SA
 
Share this answer
 
Comments
Member 11842305 20-Jul-15 16:39pm    
I have used ~ this because my Images folder is in root directory. Should I use another one?
Sergey Alexandrovich Kryukov 20-Jul-15 16:50pm    
No, if this is what you use, it should work. Just check up everything accurately.
By the way, specifying both width and height is not maintainable, use none of them (if you can) or only width or only height, otherwise you can mangle you aspect ratio.
—SA
Member 11842305 20-Jul-15 16:52pm    
It's not working, No image is showing with the relative path code.:(
Sergey Alexandrovich Kryukov 20-Jul-15 16:55pm    
Is it working an any way at all? Check up if the image is correct, has correct location, everything. It's only a matter of accurate work. After all, show the image on a page loaded in browser, without a server, to start with something.
—SA
Member 11842305 20-Jul-15 16:57pm    
Yeah as I mentioned it's working just fine with absolute path but not with the relative. There is no problem with the image.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900