Protected Sub btnUpload_Click(ByVal sender As Object, e As EventArgs) Handles btnUpload.Click
Dim filePath As String = FileUpload.PostedFile.FileName
Dim filePath2 As String = FileUploadImage.PostedFile.FileName
Dim fileName As String = Path.GetFileName(filePath)
Dim ext As String = Path.GetExtension(fileName)
Dim contenttyppe As String = String.Empty
Select Case ext
Case ".pdf"
ContentType = "application/pdf"
Exit Select
Case ".jpg"
ContentType = "image/jpg"
Exit Select
Case ".pfx"
ContentType = "image/pfx"
Exit Select
Case ".png"
ContentType = "image/png"
Exit Select
Case ".gif"
ContentType = "image/gif"
Exit Select
Case ".doc"
ContentType = "application/vnd.ms-word"
Exit Select
Case ".docx"
ContentType = "application/vnd.ms-word"
Exit Select
Case ".xls"
ContentType = "application/vnd.ms-excel"
Exit Select
Case ".xlsx"
ContentType = "application/vnd.ms-excel"
Exit Select
Case ".pfx"
ContentType = "image/pfx"
Exit Select
End Select
If contenttyppe <> String.Empty Then
Dim fs As Stream = FileUpload.PostedFile.InputStream
Dim fi As Stream = FileUploadImage.PostedFile.InputStream
Dim br As New BinaryReader(fs)
Dim br2 As New BinaryReader(fi)
Dim bytes As Byte() = br.ReadBytes(fs.Length)
Dim bytes2 As Byte() = br2.ReadBytes(fi.Length)
Dim strQuery As String = "insert into APPUSERDTL (UID,APPCODE,APPEXPIRED,SIGNIMAGE, PFKFILE,HEADUID,PRINCIPALFROM,PRINCIPALTO,EXCEPTIONUSER,LastUpdate)" _
& "VALUES('',' ','',' @FileUpload ',' @FileUploadImage','','','','','')"
Dim cmd As New SqlCommand(strQuery)
cmd.Parameters.Add("@UID", Data.SqlDbType.Int).Value = bytes
cmd.Parameters.Add("@APPCODE", Data.SqlDbType.VarChar, 50).Value = bytes
cmd.Parameters.Add("@APPEXPIRED", Data.SqlDbType.DateTime).Value = bytes
cmd.Parameters.Add("@FileUpload", Data.SqlDbType.Image).Value = FileUpload
cmd.Parameters.Add("@FileUploadImage", Data.SqlDbType.VarBinary).Value = FileUploadImage
cmd.Parameters.Add("@HEADUID", Data.SqlDbType.Int).Value = bytes
cmd.Parameters.Add("@PRINCIPALFROM", Data.SqlDbType.Money).Value = bytes
cmd.Parameters.Add("@PRINCIPALTO", Data.SqlDbType.Money).Value = bytes
cmd.Parameters.Add("@EXCEPTIONUSER", Data.SqlDbType.Bit).Value = bytes
cmd.Parameters.Add("@LastUpdate", Data.SqlDbType.DateTime).Value = bytes
InsertUpdateData(cmd)
lblMsgUpload.ForeColor = System.Drawing.Color.Green
lblMesgImage.ForeColor = System.Drawing.Color.Green
lblMsgUpload.Text = "File Upload Successfully"
lblMesgImage.Text = "File Upload Successfuly"
Else
lblMesgImage.ForeColor = System.Drawing.Color.Red
lblMesgImage.Text = "File format not recognised." _
& " Upload Image/Word/PDF/Excel formats"
End If
' delete file upload
Dim fullPath = MapPath("~/upload/") + fileName
If System.IO.File.Exists(fullPath) Then
System.IO.File.Delete(fullPath)
End If
End Sub
====================================================
Public Function InsertUpdateData(ByVal cmd As SqlCommand) As Boolean
' Dim strConnString As New DBX
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("connection").ConnectionString
Dim conn As New SqlConnection(strConnString)
cmd.CommandType = CommandType.Text
cmd.Connection = conn
Try
conn.Open()
cmd.ExecuteNonQuery()
Return True
Catch ex As Exception
Response.Write(ex.Message)
Return False
Finally
conn.Close()
conn.Dispose()
End Try
End Function
End Class