Reputation: 931
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)
imgLogo.DataBind()
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.
Upvotes: 0
Views: 12189
Reputation: 1
please try this:
imgUpload.PostedFile.SaveAs(Server.MapPath("~/Temporary/") + strImagePath))
imgLogo.ImageUrl=("~/Temporary/+ strImagePath)
It's work!
Upvotes: 0
Reputation: 25810
imgLogo.ImageUrl = Server.MapPath("..\Temporary\" + strImagePath)
This statement will be rendered as something similar to the following:
<img src="c:\...\sitelocationparent\Temporary\imagename.jpg" />
This is not the way the application should be server the image file.
It should be something like this (depending on where is the path of the aspx file):
imgLogo.ImageUrl = "../Temporary/" & imgUpload.FileName
Upvotes: 1
Reputation: 57946
Try to use your relative path, as needed to your image to be read from your browser:
imgLogo.ImageUrl = "../Temporary/" + strImagePath
Upvotes: 0