Protected Sub fu_button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles fu_button.Click
Dim fileOK As Boolean = False
If fu_image.HasFile Then
Dim selectedUser As String
selectedUser = gv_members.SelectedDataKey.Value
Dim fileExtension As String
fileExtension = System.IO.Path.GetExtension(fu_image.FileName).ToLower()
Dim userImage As String
userImage = selectedUser & fileExtension
Dim allowedExtensions As String() = {".jpg", ".jpeg", ".png", ".gif"}
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
fu_image.SaveAs(Server.MapPath("~\Resources\images\staff\" & userImage)) 'saves image file to destination as "username.ext"
Dim connectionString As String = "ConnectionString"
Dim objConn As New System.Data.SqlClient.SqlConnection(connectionString)
Dim cmdText = "INSERT INTO vw_aspnet_MembershipUsers (UserName, UserImage) VALUES (@UserName, @UserImage) WHERE (UserName = @UserName));"
Dim objCommand As New System.Data.SqlClient.SqlCommand(cmdText, objConn)
Dim objUserName As New System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.NVarChar)
objUserName.Value = selectedUser
objCommand.Parameters.Add(objUserName)
Dim objUserImage As New System.Data.SqlClient.SqlParameter("@UserImage", System.Data.SqlDbType.NVarChar)
objUserImage.Value = userImage
objCommand.Parameters.Add(objUserImage)
Try
objConn.Open()
objCommand.ExecuteNonQuery()
MsgBox("Record Inserted")
Catch exc As System.Exception
MsgBox(exc.Message())
Finally
objConn.Close()
End Try
lbl_image.Text = "File name: " & _
fu_image.PostedFile.FileName & "<br />" & _
"File Size: " & _
fu_image.PostedFile.ContentLength & _
" kb<br />" & _
"Content type: " & _
fu_image.PostedFile.ContentType & _
"<br />" & _
"File Extension is:" & _
fileExtension
Catch ex As Exception
lbl_image.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
lbl_image.Text = "You have not specified a file."
End If
End If
Page.MaintainScrollPositionOnPostBack = True
End Sub
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.