Monday, July 20, 2009

Problem with my ASP.Net Image Control

If anyone can help, please advice. I have an image control in ASP.Net and a File Upload Control. After Uploading the file successfully, the image control won't display the uploaded photo. Below is the code for the Upload Button:

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim dbAccess As DataAccess = New DataAccess
Dim con As SqlConnection = New SqlConnection(dbAccess.ConnectionString)
Dim sizeLimit As Integer = 150000 'Size limit of Photo is only 15KB
Dim saveDir As String = "Images\JobSeeker_Photos\"
Dim appPath As String = Request.PhysicalApplicationPath
Dim path As String = appPath + saveDir + fuPhoto.FileName
If fuPhoto.HasFile Then
If fuPhoto.PostedFile.ContentLength <= sizeLimit Then
fuPhoto.SaveAs(path)
lblUpload.Text = "File uploaded successfully!"
imgPhoto.ImageUrl = path
Else
lblUpload.Text = "File exceeds file limit! Photo size limit is up to 15KB only. Please edit the size of your photo."
End If
End If
End Sub

No comments:

Post a Comment