Work off this sample:
Sub btnUpload_Click (Sender as Object, e as EventArgs)
If Not (ctlFileImage.Posted is Nothing) Then
With ctlFileImage.Posted
Dim lngFileSize as Long = .ContentLength ‘//Size in Bytes upload file
Dim sContentType as String = .ContentType ‘//Returned by MINE type
Dim sFileName as String =.FileName ‘//Client File Name and Path
‘//Size Check if you do not require it then comment the following if
If (lngFileSize / 1024) > 10 Then ‘// If file size is over 10Kb
lblError.Caption += “File Size Too Much {:-o
lblError.Visible = True
Exit Sub
End If
‘//File Type Filteration: add any type and add the code to you specific type
Select Case Trim (sContentType.ToLower)
‘// Filter the file types that are sent by the browser
Case "image/gif", "image/pjpg", "image/jpeg", "image/pjpeg", "image/jpg"
Try
‘// Save the file to the server if you cannot save it then see the Errors ‘//Details Section below almost at end of the article
‘//Get only filename.ext by using IO Class no path as we use our own path
sFileName = System.IO.Path.GetFileName (.FileName)
.SaveAs (Server.MapPath (“/project/users_imgs/) & sFilename)
‘// you can also code here to store this picture in SQL server rather ‘// than saving on the server
‘// That will be my next version of this article :-)
‘// Now file is uploaded but what about the description of the picture.
‘// in ASP.NET all the controls persist their values in the server round
‘// cycles so you donot worry about the value of txtDesc it will be
‘// there as normal. So you can now use the txtDesc.Text and image
‘// path to store in the databse
Dim conn as New System.Data.SqlClient.SqlConnection (Your Connection String)
Dim cmd as New System.Data.SqlClient.SqlCommand
With cmd
.CommandText = “your update or insert query that use txtDesc.Text and other controls
.Connection = conn
.CommandType = CommandType.Text
If Conn.State = ConnectionState.Closed Then Conn.Open ()
.ExecuteNonQuery ()
End With
Catch ex As Exception
lblError.Caption += ex.ToString
lblError.Visible = True
Exit Sub
End Try
Case Else
lblError.Caption += “Invalid File Type Only Pictured are required.
lblError.Visible = True
Exit Sub
End Select
End With
End Sub