Saturday, March 24, 2012

Mapping a virtual path from code

My images get stored in my database like "~/images/myimage.jpg"

I write the image tag out in code like:
Response.Write("<img src="http://pics.10026.com/?src="" & dr.myImage & """ />")

I'm trying to figure out the best way of mapping the virtual path the the ~

Hi,

instead of using Response.Write you can dynamically add Image controls and set the ImageUrl to the data that you got from your database.

Grz, Kris.


Thanks, I'll give that a try.
(Request.ApplicationPath.Length == 1 ? string.Empty : Request.ApplicationPath) + "/Path/To/Image.aspx"

if the app path length is 1, then it is the / path, anything else willbe /SomeAppPath, so you don't need the / for the empty path.

0 comments:

Post a Comment