Bind ASP.NET Image Control

M

markcash

I am trying to bind an ASP.NET image control to images stored locally
on the hard drive of the web server. The images will be frequently
changing so I am dynamically creating the filename. I am using
File.Exists and it returns true, but when I try to bind it to the
control, I am not getting the image to display. But if I view the
source it shows the correct path. I have tried creating a virtual
directory and also accessing the drive drectly.

Any ideas?

Here is my code:

Dim strImage As String = "B" & Left(strBookingNumber, 4) &
Right("0000000000" & Mid(strBookingNumber, 6), 10) & ".001.jpg"
Dim strImagePath As String = "../MugShots/"
'Dim strImagePath As String = "C:\MugShot\"
Dim strImageName As String = strImagePath & strImage
If File.Exists(strImageName) Then
Me.imgMugShot.ImageUrl = strImageName
End If
 
E

Eliyahu Goldin

You should use 2 different paths. File.Exists works with a physical path
whereas ImageUrl is a virtual path.
 
M

markcash

I was not aware of that, thanks.

That works great.

Thanks again for your help!

Mark

Eliyahu said:
You should use 2 different paths. File.Exists works with a physical path
whereas ImageUrl is a virtual path.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I am trying to bind an ASP.NET image control to images stored locally
on the hard drive of the web server. The images will be frequently
changing so I am dynamically creating the filename. I am using
File.Exists and it returns true, but when I try to bind it to the
control, I am not getting the image to display. But if I view the
source it shows the correct path. I have tried creating a virtual
directory and also accessing the drive drectly.

Any ideas?

Here is my code:

Dim strImage As String = "B" & Left(strBookingNumber, 4) &
Right("0000000000" & Mid(strBookingNumber, 6), 10) & ".001.jpg"
Dim strImagePath As String = "../MugShots/"
'Dim strImagePath As String = "C:\MugShot\"
Dim strImageName As String = strImagePath & strImage
If File.Exists(strImageName) Then
Me.imgMugShot.ImageUrl = strImageName
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top