I am trying to set an image dynamically. Image control is not displaying the image but it is displaying the alternate text. I'm using VS 2008 with vb.net. I used information from this post to construct the code. During debug the file path is correct.
vb Code:
Dim strImgURL As String = "C:\fldr1\fldr2\Projfldr3\images\emps\" 'local dev path where visual studio solution is located
Dim filename As String = System.IO.Path.Combine(strImgURL, Session("EmpID").ToString() & ".jpg")
If (File.Exists(filename)) Then
imgEmp.ImageUrl = filename
Else
filename = System.IO.Path.Combine(strImgURL, "99999.jpg")
imgEmp.ImageUrl = filename
End If
aspx:
<asp:image id="imgEmp" Runat="server" Height="100px" Width="77px"
AlternateText="Employee's picture" />
Is it wrong to use "IO.Path.combine" when passing to ImageUrl?
UPDATE: Still working on this with lessons learned from this thread and this thread using MapPath property to set the path to images. The mappath should theoretically detect file path to the images folder in whatever environment I'm testing.
The only way I can get an image to show is if I hard-code filename value like below (removing any mappath code and system.io.path.combine() code entirely). btw I am taking a Int session variable, Session("EmpID")
converting to string to create the filename property (e.g. 12345) - none of the conversion methods I'm using are effective:
1. Session("EmpID").ToString() (or Convert.ToString(Session("EmpID"))
2. strEmpID =Session("EmpID").ToString() + ".jpg"
strImgURL = "http://server/images/" + strEmpID + ".jpg"