Vibin Jith Vibin Jith - 2 months ago 18
ASP.NET (C#) Question

How to Display Image in the Image Control using FileUpload?

I just call this function on a button click.
I also want to know in which event of FileUpload I can call this function.

Function upload() As Boolean
Dim img As FileUpload = CType(imgUpload, FileUpload)
imgByte = Nothing
If img.HasFile AndAlso Not img.PostedFile Is Nothing Then
Dim File As HttpPostedFile = imgUpload.PostedFile
imgByte = New Byte(File.ContentLength - 1) {}
File.InputStream.Read(imgByte, 0, File.ContentLength)
End If
Dim strImagePath As String = imgUpload.FileName
imgUpload.PostedFile.SaveAs(Server.MapPath("..\Temporary\" + strImagePath))
imgLogo.ImageUrl = Server.MapPath("..\Temporary\" + strImagePath)
End Function

Even after setting the url, image is not showing.I am sure that image file is created on the server and the path specified is right.


Try to use your relative path, as needed to your image to be read from your browser:

imgLogo.ImageUrl = "../Temporary/" + strImagePath